home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / term-source.lha / termInit.c < prev    next >
C/C++ Source or Header  |  1995-09-29  |  115KB  |  5,384 lines

  1. /*
  2. **    termInit.c
  3. **
  4. **    Program initialization and shutdown routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* This variable helps us to remember whether the fast!
  13.      * macro panel was open or not.
  14.      */
  15.  
  16. STATIC BYTE HadFastMacros = FALSE;
  17.  
  18.     /* Remember whether we did pen allocation or not. */
  19.  
  20. STATIC BYTE AllocatedPens = FALSE;
  21.  
  22.     /* SafeOpenLibrary(STRPTR Name,LONG Version):
  23.      *
  24.      *    Try to open a library, but if there already is
  25.      *    a version in memory that's older than the release
  26.      *    we want flush it out first.
  27.      */
  28.  
  29. struct Library * __regargs
  30. SafeOpenLibrary(STRPTR Name,LONG Version)
  31. {
  32.     struct Library *Base;
  33.  
  34.     Forbid();
  35.  
  36.         /* Is this library already in memory? */
  37.  
  38.     if(Base = (struct Library *)FindName(&SysBase -> LibList,FilePart(Name)))
  39.     {
  40.             /* An old release? */
  41.  
  42.         if(Base -> lib_Version < Version)
  43.         {
  44.                 /* Flush it out. */
  45.  
  46.             RemLibrary(Base);
  47.         }
  48.     }
  49.  
  50.     Permit();
  51.  
  52.         /* Now reopen the library. */
  53.  
  54.     return(OpenLibrary(Name,Version));
  55. }
  56.  
  57.     /* TTYResize():
  58.      *
  59.      *    Signal AmigaUW that the window size has changed.
  60.      */
  61.  
  62. VOID
  63. TTYResize()
  64. {
  65.     if(Window)
  66.     {
  67.         BOOL    GotIt = TRUE;
  68.         LONG    Lines,Columns;
  69.  
  70.         if(XEmulatorBase && XEM_IO)
  71.         {
  72.             if(XEmulatorBase -> lib_Version >= 4)
  73.             {
  74.                 ULONG Result = XEmulatorInfo(XEM_IO,XEMI_CONSOLE_DIMENSIONS);
  75.  
  76.                 Columns    = XEMI_EXTRACT_COLUMNS(Result);
  77.                 Lines    = XEMI_EXTRACT_LINES(Result);
  78.             }
  79.             else
  80.                 GotIt = FALSE;
  81.         }
  82.         else
  83.         {
  84.             Columns    = LastColumn + 1;
  85.             Lines    = LastLine + 1;
  86.         }
  87.  
  88.         if(GotIt && WriteRequest)
  89.         {
  90.             WriteRequest -> IOSer . io_Command    = UWCMD_TTYRESIZE;
  91.             WriteRequest -> IOSer . io_Data        = (APTR)((Columns << 16) | (Lines));
  92.             WriteRequest -> IOSer . io_Length    = (WindowWidth << 16) | (WindowHeight);
  93.  
  94.             DoIO(WriteRequest);
  95.         }
  96.     }
  97. }
  98.  
  99.     /* LoadKeyMap(STRPTR Name):
  100.      *
  101.      *    Load a keymap file from disk.
  102.      */
  103.  
  104. STATIC struct KeyMap * __regargs
  105. LoadKeyMap(STRPTR Name)
  106. {
  107.     struct KeyMapResource    *KeyMapResource;
  108.     struct KeyMap        *Map = NULL;
  109.  
  110.         /* Try to get access to the list of currently loaded
  111.          * keymap files.
  112.          */
  113.  
  114.     if(KeyMapResource = (struct KeyMapResource *)OpenResource("keymap.resource"))
  115.     {
  116.         struct KeyMapNode *Node;
  117.  
  118.             /* Try to find the keymap in the list. */
  119.  
  120.         Forbid();
  121.  
  122.         if(Node = (struct KeyMapNode *)FindName(&KeyMapResource -> kr_List,FilePart(Config -> TerminalConfig -> KeyMapFileName)))
  123.             Map = &Node -> kn_KeyMap;
  124.  
  125.         Permit();
  126.     }
  127.  
  128.         /* Still no keymap available? */
  129.  
  130.     if(!Map)
  131.     {
  132.         APTR OldPtr = ThisProcess -> pr_WindowPtr;
  133.  
  134.             /* Disable DOS requesters. */
  135.  
  136.         ThisProcess -> pr_WindowPtr = (APTR)-1;
  137.  
  138.             /* Unload the old keymap code. */
  139.  
  140.         if(KeySegment)
  141.             UnLoadSeg(KeySegment);
  142.  
  143.             /* Try to load the keymap from the
  144.              * name the user entered.
  145.              */
  146.  
  147.         if(!(KeySegment = LoadSeg(Config -> TerminalConfig -> KeyMapFileName)))
  148.         {
  149.                 /* Second try: load it from
  150.                   * the standard keymaps drawer.
  151.                   */
  152.  
  153.             strcpy(SharedBuffer,"KEYMAPS:");
  154.  
  155.             if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  156.             {
  157.                 if(!(KeySegment = LoadSeg(SharedBuffer)))
  158.                 {
  159.                     strcpy(SharedBuffer,"Devs:Keymaps");
  160.  
  161.                     if(AddPart(SharedBuffer,FilePart(Config -> TerminalConfig -> KeyMapFileName),MAX_FILENAME_LENGTH))
  162.                         KeySegment = LoadSeg(SharedBuffer);
  163.                 }
  164.             }
  165.         }
  166.  
  167.             /* Did we get the keymap file? */
  168.  
  169.         if(KeySegment)
  170.         {
  171.             struct KeyMapNode *Node = (struct KeyMapNode *)&((ULONG *)BADDR(KeySegment))[1];
  172.  
  173.             Map = &Node -> kn_KeyMap;
  174.         }
  175.  
  176.             /* Enable DOS requesters again. */
  177.  
  178.         ThisProcess -> pr_WindowPtr = OldPtr;
  179.     }
  180.     else
  181.     {
  182.         if(KeySegment)
  183.         {
  184.             UnLoadSeg(KeySegment);
  185.  
  186.             KeySegment = NULL;
  187.         }
  188.     }
  189.  
  190.     return(Map);
  191. }
  192.  
  193.     /* DeleteOffsetTables(VOID):
  194.      *
  195.      *    Delete the line multiplication tables.
  196.      */
  197.  
  198. STATIC VOID
  199. DeleteOffsetTables(VOID)
  200. {
  201.     if(OffsetXTable)
  202.     {
  203.         FreeVecPooled(OffsetXTable);
  204.  
  205.         OffsetXTable = NULL;
  206.     }
  207.  
  208.     if(OffsetYTable)
  209.     {
  210.         FreeVecPooled(OffsetYTable);
  211.  
  212.         OffsetYTable = NULL;
  213.     }
  214. }
  215.  
  216.     /* CreateOffsetTables(VOID):
  217.      *
  218.      *    Allocate the line multiplication tables.
  219.      */
  220.  
  221. STATIC BYTE
  222. CreateOffsetTables(VOID)
  223. {
  224.     LONG    Width    = (Window -> WScreen -> Width  + TextFontWidth)  * 2 / TextFontWidth,
  225.         Height    = (Window -> WScreen -> Height + TextFontHeight) * 2 / TextFontHeight;
  226.  
  227.     DeleteOffsetTables();
  228.  
  229.     if(OffsetXTable = (LONG *)AllocVecPooled(Width * sizeof(LONG),MEMF_ANY))
  230.     {
  231.         if(OffsetYTable = (LONG *)AllocVecPooled(Height * sizeof(LONG),MEMF_ANY))
  232.         {
  233.             LONG i,j;
  234.  
  235.             for(i = j = 0 ; i < Width ; i++, j += TextFontWidth)
  236.                 OffsetXTable[i] = j;
  237.  
  238.             for(i = j = 0 ; i < Height ; i++, j += TextFontHeight)
  239.                 OffsetYTable[i] = j;
  240.  
  241.             return(TRUE);
  242.         }
  243.     }
  244.  
  245.     DeleteOffsetTables();
  246.  
  247.     return(FALSE);
  248. }
  249.  
  250.     /* CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst):
  251.      *
  252.      *    Copy single menu item flags from one menu strip
  253.      *    to another.
  254.      */
  255.  
  256. STATIC VOID __regargs
  257. CopyItemFlags(struct MenuItem *Src,struct MenuItem *Dst)
  258. {
  259.     while(Src && Dst)
  260.     {
  261.         if(Src -> SubItem)
  262.             CopyItemFlags(Src -> SubItem,Dst -> SubItem);
  263.  
  264.         Dst -> Flags = Src -> Flags;
  265.  
  266.         Src = Src -> NextItem;
  267.         Dst = Dst -> NextItem;
  268.     }
  269. }
  270.  
  271.     /* CopyMenuFlags(struct Menu *Src,struct Menu *Dst):
  272.      *
  273.      *    Copy menu flags from one menu strip to
  274.      *    another.
  275.      */
  276.  
  277. STATIC VOID __regargs
  278. CopyMenuFlags(struct Menu *Src,struct Menu *Dst)
  279. {
  280.     struct MenuItem *SrcItem,*DstItem;
  281.  
  282.     while(Src && Dst)
  283.     {
  284.             // Don't touch the quick dial menu. If CopyMenuFlags()
  285.             // is called its contents are likely to have changed
  286.  
  287.         if((ULONG)GTMENU_USERDATA(Src) == DIAL_MENU_LIMIT)
  288.             break;
  289.  
  290.         SrcItem = Src -> FirstItem;
  291.         DstItem = Dst -> FirstItem;
  292.  
  293.         while(SrcItem && DstItem)
  294.         {
  295.             CopyItemFlags(SrcItem,DstItem);
  296.  
  297.             SrcItem = SrcItem -> NextItem;
  298.             DstItem = DstItem -> NextItem;
  299.         }
  300.  
  301.         Src = Src -> NextMenu;
  302.         Dst = Dst -> NextMenu;
  303.     }
  304. }
  305.  
  306.     /* AttachMenu():
  307.      *
  308.      *    Rebuild the main menu (if necessary) and attach it to the other windows.
  309.      */
  310.  
  311. BOOL __regargs
  312. AttachMenu(struct Menu *ThisMenu)
  313. {
  314.     if(!ThisMenu)
  315.         ThisMenu = BuildMenu();
  316.  
  317.     if(ThisMenu)
  318.     {
  319.         if(Menu)
  320.         {
  321.             CopyMenuFlags(Menu,ThisMenu);
  322.  
  323.             if(Window)
  324.                 ClearMenuStrip(Window);
  325.  
  326.             if(StatusWindow)
  327.                 ClearMenuStrip(StatusWindow);
  328.  
  329.             if(FastWindow)
  330.                 ClearMenuStrip(FastWindow);
  331.  
  332.             LT_DisposeMenu(Menu);
  333.         }
  334.  
  335.         Menu = ThisMenu;
  336.  
  337.         if(Window)
  338.             SetMenuStrip(Window,Menu);
  339.  
  340.         if(StatusWindow)
  341.             SetMenuStrip(StatusWindow,Menu);
  342.  
  343.         if(FastWindow)
  344.             SetMenuStrip(FastWindow,Menu);
  345.  
  346.         return(TRUE);
  347.     }
  348.     else
  349.         return(FALSE);
  350. }
  351.  
  352.     /* DisconnectDialMenu():
  353.      *
  354.      *    Disconnect the quick dial menu as its contents will
  355.      *    be invalid. This may happen if `term' fails to rebuild
  356.      *    the main menu due to memory shortage. Please note that
  357.      *    disconnecting the menu this way is legal only for menus
  358.      *    created by gtlayout.library.
  359.      */
  360.  
  361. VOID
  362. DisconnectDialMenu()
  363. {
  364.     if(Menu)
  365.     {
  366.         struct Menu *ThisMenu,*LastMenu = NULL;
  367.  
  368.         if(Window)
  369.             ClearMenuStrip(Window);
  370.  
  371.         if(StatusWindow)
  372.             ClearMenuStrip(StatusWindow);
  373.  
  374.         if(FastWindow)
  375.             ClearMenuStrip(FastWindow);
  376.  
  377.         for(ThisMenu = Menu ; ThisMenu ; LastMenu = ThisMenu, ThisMenu = ThisMenu -> NextMenu)
  378.         {
  379.             if(!ThisMenu -> NextMenu && (ULONG)GTMENU_USERDATA(ThisMenu) == DIAL_MENU_LIMIT)
  380.             {
  381.                 LastMenu -> NextMenu = NULL;
  382.                 break;
  383.             }
  384.         }
  385.  
  386.         if(Window)
  387.             SetMenuStrip(Window,Menu);
  388.  
  389.         if(StatusWindow)
  390.             SetMenuStrip(StatusWindow,Menu);
  391.  
  392.         if(FastWindow)
  393.             SetMenuStrip(FastWindow,Menu);
  394.     }
  395. }
  396.  
  397.     /* BuildMenu():
  398.      *
  399.      *    Create the menu strip, including the quick dial menu.
  400.      */
  401.  
  402. struct Menu *
  403. BuildMenu()
  404. {
  405.     LONG PhoneCount,Grouped,NotGrouped,Groups,Separator,i,j;
  406.  
  407.     PhoneCount = 0;
  408.  
  409.         // Add the quick dial entries. This is not your basic
  410.         // O(N) algorithm :-/
  411.  
  412.     if(Phonebook)
  413.     {
  414.         Grouped = NotGrouped = Groups = 0;
  415.  
  416.         for(i = 0 ; PhoneCount < DIAL_MENU_MAX && i < NumPhoneEntries ; i++)
  417.         {
  418.             if(Phonebook[i] -> Header -> QuickMenu)
  419.             {
  420.                 PhoneCount++;
  421.  
  422.                     // Check if this entry is in a group
  423.  
  424.                 if(Phonebook[i] -> ThisGroup)
  425.                 {
  426.                     BOOL Unique = TRUE;
  427.  
  428.                     Grouped++;
  429.  
  430.                         // Are there other entries in this group?
  431.  
  432.                     for(j = 0 ; j < i ; j++)
  433.                     {
  434.                         if(Phonebook[j] -> ThisGroup && Phonebook[j] -> ThisGroup == Phonebook[i] -> ThisGroup)
  435.                         {
  436.                             Unique = FALSE;
  437.  
  438.                             break;
  439.                         }
  440.                     }
  441.  
  442.                         // Is this the only one?
  443.  
  444.                     if(Unique)
  445.                         Groups++;
  446.                 }
  447.                 else
  448.                     NotGrouped++;
  449.             }
  450.         }
  451.  
  452.             // Will we need to mix grouped and ungrouped entries?
  453.  
  454.         if(Grouped && NotGrouped)
  455.             Separator = 1;
  456.         else
  457.             Separator = 0;
  458.     }
  459.  
  460.         // Don't do the work if no quick dial menu needs to be built
  461.  
  462.     if(PhoneCount)
  463.     {
  464.         struct NewMenu *NewMenu;
  465.  
  466.             // Allocate new menu prototypes
  467.  
  468.         if(NewMenu = (struct NewMenu *)AllocVecPooled((NumMenuEntries + PhoneCount + Groups + Separator) * sizeof(struct NewMenu),MEMF_ANY | MEMF_CLEAR))
  469.         {
  470.             struct Menu    *ThisMenu;
  471.             LONG         Count;
  472.  
  473.                 // Reset the menu type
  474.  
  475.             TermMenu[NumMenuEntries - 2] . nm_Type        = NM_TITLE;
  476.             TermMenu[NumMenuEntries - 2] . nm_UserData    = (APTR)DIAL_MENU_LIMIT;
  477.  
  478.             CopyMem(TermMenu,NewMenu,NumMenuEntries * sizeof(struct NewMenu));
  479.  
  480.             FirstDialMenu = -1;
  481.  
  482.             Count = NumMenuEntries - 1;
  483.  
  484.                 // Are we to pull entries just from one single group?
  485.  
  486.             if(Grouped == 1 && !NotGrouped)
  487.             {
  488.                 for(i = 0 ; i < NumPhoneEntries ; i++)
  489.                 {
  490.                     if(Phonebook[i] -> Header -> QuickMenu)
  491.                     {
  492.                         NewMenu[Count] . nm_Type    = NM_ITEM;
  493.                         NewMenu[Count] . nm_Label    = Phonebook[i] -> Header -> Name;
  494.                         NewMenu[Count] . nm_Flags    = CHECKIT;
  495.                         NewMenu[Count] . nm_UserData    = (APTR)(DIAL_MENU_LIMIT + i);
  496.  
  497.                         Count++;
  498.  
  499.                         if(FirstDialMenu == -1)
  500.                             FirstDialMenu = DIAL_MENU_LIMIT + i;
  501.                     }
  502.                 }
  503.             }
  504.             else
  505.             {
  506.                     // First step: collect the entries that don't belong into groups
  507.  
  508.                 for(i = 0 ; i < NumPhoneEntries ; i++)
  509.                 {
  510.                     if(Phonebook[i] -> Header -> QuickMenu && !Phonebook[i] -> ThisGroup)
  511.                     {
  512.                         NewMenu[Count] . nm_Type    = NM_ITEM;
  513.                         NewMenu[Count] . nm_Label    = Phonebook[i] -> Header -> Name;
  514.                         NewMenu[Count] . nm_Flags    = CHECKIT;
  515.                         NewMenu[Count] . nm_UserData    = (APTR)(DIAL_MENU_LIMIT + i);
  516.  
  517.                         Count++;
  518.  
  519.                         if(FirstDialMenu == -1)
  520.                             FirstDialMenu = DIAL_MENU_LIMIT + i;
  521.                     }
  522.                 }
  523.  
  524.                     // If there needs to be a separator, add it
  525.  
  526.                 if(Separator)
  527.                 {
  528.                     NewMenu[Count] . nm_Type    = NM_ITEM;
  529.                     NewMenu[Count] . nm_Label    = NM_BARLABEL;
  530.                     NewMenu[Count] . nm_Flags    = NULL;
  531.                     NewMenu[Count] . nm_UserData    = NULL;
  532.  
  533.                     Count++;
  534.                 }
  535.  
  536.                     // Second step: collect the remaining entries that belong into groups
  537.  
  538.                 for(i = 0 ; i < NumPhoneEntries ; i++)
  539.                 {
  540.                     if(Phonebook[i] -> Header -> QuickMenu && Phonebook[i] -> ThisGroup)
  541.                     {
  542.                         BOOL Unique = TRUE;
  543.  
  544.                         for(j = 0 ; j < i ; j++)
  545.                         {
  546.                             if(Phonebook[j] -> Header -> QuickMenu && Phonebook[j] -> ThisGroup && Phonebook[j] -> ThisGroup == Phonebook[i] -> ThisGroup)
  547.                             {
  548.                                 Unique = FALSE;
  549.                                 break;
  550.                             }
  551.                         }
  552.  
  553.                         if(Unique)
  554.                         {
  555.                             LONG k;
  556.  
  557.                             NewMenu[Count] . nm_Type    = NM_ITEM;
  558.                             NewMenu[Count] . nm_Label    = Phonebook[i] -> ThisGroup -> LocalName;
  559.                             NewMenu[Count] . nm_Flags    = NULL;
  560.                             NewMenu[Count] . nm_UserData    = NULL;
  561.  
  562.                             Count++;
  563.  
  564.                             for(k = i ; k < NumPhoneEntries ; k++)
  565.                             {
  566.                                 if(Phonebook[k] -> Header -> QuickMenu && Phonebook[k] -> ThisGroup == Phonebook[i] -> ThisGroup)
  567.                                 {
  568.                                     NewMenu[Count] . nm_Type    = NM_SUB;
  569.                                     NewMenu[Count] . nm_Label    = Phonebook[k] -> Header -> Name;
  570.                                     NewMenu[Count] . nm_Flags    = CHECKIT;
  571.                                     NewMenu[Count] . nm_UserData    = (APTR)(DIAL_MENU_LIMIT + k);
  572.  
  573.                                     Count++;
  574.  
  575.                                     if(FirstDialMenu == -1)
  576.                                         FirstDialMenu = DIAL_MENU_LIMIT + k;
  577.                                 }
  578.                             }
  579.                         }
  580.                     }
  581.                 }
  582.  
  583.             }
  584.  
  585.             NewMenu[Count] . nm_Type = NM_END;
  586.  
  587.                 // Now layout the menu
  588.  
  589.             ThisMenu = LT_NewMenuTemplate(Window -> WScreen,NULL,AmigaGlyph,CheckGlyph,NULL,NewMenu);
  590.  
  591.                 // We don't need this any more
  592.  
  593.             FreeVecPooled(NewMenu);
  594.  
  595.                 // Successful?
  596.  
  597.             if(ThisMenu)
  598.                 return(ThisMenu);
  599.         }
  600.     }
  601.  
  602.         // Disconnect the quick dial menu
  603.  
  604.     TermMenu[NumMenuEntries - 2] . nm_Type = NM_END;
  605.  
  606.         // Create the default menu strip
  607.  
  608.     return(LT_NewMenuTemplate(Window -> WScreen,NULL,AmigaGlyph,CheckGlyph,NULL,TermMenu));
  609. }
  610.  
  611.     /* UpdateTerminalLimits():
  612.      *
  613.      *    Check the current window size and extract the
  614.      *    size and position of the usable window rectangle.
  615.      */
  616.  
  617. VOID
  618. UpdateTerminalLimits()
  619. {
  620.     WindowLeft    = Window -> BorderLeft;
  621.     WindowTop    = Window -> BorderTop;
  622.  
  623.     WindowWidth    = Window -> Width - (Window -> BorderLeft + Window -> BorderRight);
  624.     WindowHeight    = Window -> Height - (Window -> BorderTop + Window -> BorderBottom);
  625.  
  626.     if(StatusWindow)
  627.     {
  628.         StatusDisplayLeft    = StatusWindow -> BorderLeft;
  629.         StatusDisplayTop    = StatusWindow -> BorderTop;
  630.         StatusDisplayWidth    = StatusWindow -> Width - (StatusWindow -> BorderLeft + StatusWindow -> BorderRight);
  631.         StatusDisplayHeight    = StatusWindow -> Height - (StatusWindow -> BorderTop + StatusWindow -> BorderBottom);
  632.     }
  633.     else
  634.     {
  635.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  636.         {
  637.             StatusDisplayLeft    = WindowLeft;
  638.             StatusDisplayTop    = Window -> Height - (Window -> BorderBottom + StatusDisplayHeight);
  639.             StatusDisplayWidth    = WindowWidth;
  640.  
  641.             WindowHeight -= StatusDisplayHeight;
  642.         }
  643.     }
  644.  
  645.     if(ChatMode && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  646.     {
  647.         if(CreateChatGadget())
  648.         {
  649.             UpdateChatGadget();
  650.  
  651.             WindowHeight -= (UserFontHeight + 2);
  652.  
  653.             ActivateChat(FALSE);
  654.         }
  655.     }
  656. }
  657.  
  658.     /* Current2DefaultPalette(struct Configuration *SomeConfig):
  659.      *
  660.      *    Copy the current colour palette into the
  661.      *    default tables.
  662.      */
  663.  
  664. VOID __regargs
  665. Current2DefaultPalette(struct Configuration *SomeConfig)
  666. {
  667.     ColourTable    *Table = NULL;
  668.     UWORD        *Colour12;
  669.  
  670.     if(!SomeConfig)
  671.         SomeConfig = Config;
  672.  
  673.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  674.     {
  675.         case COLOUR_EIGHT:
  676.  
  677.             if(Kick30)
  678.             {
  679.                 if(!ANSIColourTable)
  680.                     ANSIColourTable = CreateColourTable(8,ANSIColours,NULL);
  681.  
  682.                 Table = ANSIColourTable;
  683.             }
  684.  
  685.             Colour12 = ANSIColours;
  686.  
  687.             break;
  688.  
  689.         case COLOUR_SIXTEEN:
  690.  
  691.             if(Kick30)
  692.             {
  693.                 if(!EGAColourTable)
  694.                     EGAColourTable = CreateColourTable(16,EGAColours,NULL);
  695.  
  696.                 Table = EGAColourTable;
  697.             }
  698.  
  699.             Colour12 = EGAColours;
  700.  
  701.             break;
  702.  
  703.         case COLOUR_AMIGA:
  704.  
  705.             if(Kick30)
  706.             {
  707.                 if(!DefaultColourTable)
  708.                     DefaultColourTable = CreateColourTable(16,DefaultColours,NULL);
  709.  
  710.                 Table = DefaultColourTable;
  711.             }
  712.  
  713.             Colour12 = DefaultColours;
  714.  
  715.             break;
  716.  
  717.         case COLOUR_MONO:
  718.  
  719.             if(Kick30)
  720.             {
  721.                 if(!MonoColourTable)
  722.                     MonoColourTable = CreateColourTable(2,AtomicColours,NULL);
  723.  
  724.                 Table = MonoColourTable;
  725.             }
  726.  
  727.             Colour12 = AtomicColours;
  728.             break;
  729.     }
  730.  
  731.     if(Table)
  732.     {
  733.         if(SomeConfig -> ScreenConfig -> UseColours96)
  734.             Colour96xColourTable(SomeConfig -> ScreenConfig -> Colours96,Table,Table -> NumColours);
  735.         else
  736.         {
  737.             Colour12xColourTable(SomeConfig -> ScreenConfig -> Colours,Table,Table -> NumColours);
  738.  
  739.             Colour12x96(SomeConfig -> ScreenConfig -> Colours,SomeConfig -> ScreenConfig -> Colours96,16);
  740.  
  741.             SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  742.         }
  743.     }
  744.  
  745.     CopyMem(SomeConfig -> ScreenConfig -> Colours,Colour12,16 * sizeof(UWORD));
  746. }
  747.  
  748.     /* Default2CurrentPalette(struct Configuration *SomeConfig):
  749.      *
  750.      *    Copy the default palette to the current palette.
  751.      */
  752.  
  753. VOID __regargs
  754. Default2CurrentPalette(struct Configuration *SomeConfig)
  755. {
  756.     ColourTable    *Table = NULL;
  757.     UWORD        *Colour12;
  758.  
  759.     if(!SomeConfig)
  760.         SomeConfig = Config;
  761.  
  762.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  763.     {
  764.         case COLOUR_EIGHT:
  765.  
  766.             Table        = ANSIColourTable;
  767.             Colour12    = ANSIColours;
  768.  
  769.             break;
  770.  
  771.         case COLOUR_SIXTEEN:
  772.  
  773.             Table        = EGAColourTable;
  774.             Colour12    = EGAColours;
  775.  
  776.             break;
  777.  
  778.         case COLOUR_AMIGA:
  779.  
  780.             Table        = DefaultColourTable;
  781.             Colour12    = DefaultColours;
  782.  
  783.             break;
  784.  
  785.         case COLOUR_MONO:
  786.  
  787.             Table        = MonoColourTable;
  788.             Colour12    = AtomicColours;
  789.             break;
  790.     }
  791.  
  792.     if(Table)
  793.     {
  794.         ColourTablex96(Table,SomeConfig -> ScreenConfig -> Colours96);
  795.  
  796.         CopyMem(Colour12,SomeConfig -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  797.  
  798.         SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  799.     }
  800.     else
  801.     {
  802.         CopyMem(Colour12,SomeConfig -> ScreenConfig -> Colours,16 * sizeof(UWORD));
  803.  
  804.         SomeConfig -> ScreenConfig -> UseColours96 = FALSE;
  805.     }
  806. }
  807.  
  808.     /* PaletteSetup():
  809.      *
  810.      *    Set up colour palettes.
  811.      */
  812.  
  813. VOID __regargs
  814. PaletteSetup(struct Configuration *SomeConfig)
  815. {
  816.     WORD i;
  817.  
  818.     if(!SomeConfig)
  819.         SomeConfig = Config;
  820.  
  821.     if(SomeConfig -> ScreenConfig -> UseColours96)
  822.     {
  823.         Colour96x12(SomeConfig -> ScreenConfig -> Colours96,NormalColours,16);
  824.         Colour96x12(SomeConfig -> ScreenConfig -> Colours96,SomeConfig -> ScreenConfig -> Colours,16);
  825.     }
  826.     else
  827.     {
  828.         CopyMem(SomeConfig -> ScreenConfig -> Colours,NormalColours,16 * sizeof(UWORD));
  829.  
  830.         Colour12x96(NormalColours,SomeConfig -> ScreenConfig -> Colours96,16);
  831.  
  832.         SomeConfig -> ScreenConfig -> UseColours96 = TRUE;
  833.     }
  834.  
  835.     CopyMem(NormalColours,&NormalColours[16],16 * sizeof(UWORD));
  836.     CopyMem(NormalColours,BlinkColours,32 * sizeof(UWORD));
  837.  
  838.     switch(SomeConfig -> ScreenConfig -> ColourMode)
  839.     {
  840.         case COLOUR_EIGHT:
  841.  
  842.             if(SomeConfig -> ScreenConfig -> Blinking)
  843.             {
  844.                 for(i = 0 ; i < 8 ; i++)
  845.                     BlinkColours[8 + i] = BlinkColours[0];
  846.  
  847.                 PaletteSize = 16;
  848.             }
  849.             else
  850.                 PaletteSize = 8;
  851.  
  852.             break;
  853.  
  854.         case COLOUR_SIXTEEN:
  855.  
  856.             if(GetBitMapDepth(Window -> WScreen -> RastPort . BitMap) >= 5 && SomeConfig -> ScreenConfig -> Blinking)
  857.             {
  858.                 for(i = 0 ; i < 16 ; i++)
  859.                     BlinkColours[16 + i] = BlinkColours[0];
  860.  
  861.                 PaletteSize = 32;
  862.             }
  863.             else
  864.                 PaletteSize = 16;
  865.  
  866.             break;
  867.  
  868.         case COLOUR_AMIGA:
  869.  
  870.             BlinkColours[3] = BlinkColours[0];
  871.  
  872.             PaletteSize = 4;
  873.  
  874.             break;
  875.  
  876.         case COLOUR_MONO:
  877.  
  878.             PaletteSize = 2;
  879.             break;
  880.     }
  881.  
  882.     if(Kick30)
  883.     {
  884.         if(NormalColourTable)
  885.             DeleteColourTable(NormalColourTable);
  886.  
  887.         if(BlinkColourTable)
  888.             DeleteColourTable(BlinkColourTable);
  889.  
  890.         if(NormalColourTable = CreateColourTable(PaletteSize,NULL,SomeConfig -> ScreenConfig -> Colours96))
  891.         {
  892.             if(PaletteSize == 2 || !SomeConfig -> ScreenConfig -> Blinking)
  893.                 BlinkColourTable = NULL;
  894.             else
  895.             {
  896.                 if(BlinkColourTable = CreateColourTable(PaletteSize,NULL,NULL))
  897.                 {
  898.                     switch(SomeConfig -> ScreenConfig -> ColourMode)
  899.                     {
  900.                         case COLOUR_EIGHT:
  901.  
  902.                             for(i = 0 ; i < 8 ; i++)
  903.                             {
  904.                                 CopyColourEntry(NormalColourTable,NormalColourTable,i,8 + i);
  905.                                 CopyColourEntry(NormalColourTable,BlinkColourTable,i,i);
  906.                                 CopyColourEntry(NormalColourTable,BlinkColourTable,0,8 + i);
  907.                             }
  908.  
  909.                             break;
  910.  
  911.                         case COLOUR_SIXTEEN:
  912.  
  913.                             if(GetBitMapDepth(Window -> WScreen -> RastPort . BitMap) >= 5)
  914.                             {
  915.                                 for(i = 0 ; i < 16 ; i++)
  916.                                 {
  917.                                     CopyColourEntry(NormalColourTable,NormalColourTable,i,16 + i);
  918.                                     CopyColourEntry(NormalColourTable,BlinkColourTable,i,i);
  919.                                     CopyColourEntry(NormalColourTable,BlinkColourTable,0,16 + i);
  920.                                 }
  921.                             }
  922.                             else
  923.                             {
  924.                                 DeleteColourTable(BlinkColourTable);
  925.  
  926.                                 BlinkColourTable = NULL;
  927.                             }
  928.  
  929.                             break;
  930.  
  931.                         case COLOUR_AMIGA:
  932.  
  933.                             for(i = 0 ; i < 4 ; i++)
  934.                                 CopyColourEntry(NormalColourTable,BlinkColourTable,i,i);
  935.  
  936.                             CopyColourEntry(BlinkColourTable,BlinkColourTable,0,3);
  937.  
  938.                             break;
  939.                     }
  940.                 }
  941.                 else
  942.                 {
  943.                     DeleteColourTable(NormalColourTable);
  944.  
  945.                     NormalColourTable = NULL;
  946.                 }
  947.             }
  948.         }
  949.     }
  950. }
  951.  
  952.     /* ResetCursorKeys(struct CursorKeys *Keys):
  953.      *
  954.      *    Reset cursor key assignments to defaults.
  955.      */
  956.  
  957. VOID __regargs
  958. ResetCursorKeys(struct CursorKeys *Keys)
  959. {
  960.     STATIC STRPTR Defaults[4] =
  961.     {
  962.         "\\e[A",
  963.         "\\e[B",
  964.         "\\e[C",
  965.         "\\e[D"
  966.     };
  967.  
  968.     WORD i,j;
  969.  
  970.     for(i = 0 ; i < 4 ; i++)
  971.     {
  972.         for(j = 0 ; j < 4 ; j++)
  973.             strcpy(Keys -> Keys[j][i],Defaults[i]);
  974.     }
  975. }
  976.  
  977.     /* ResetMacroKeys(struct MacroKeys *Keys):
  978.      *
  979.      *    Reset the macro key assignments to defaults.
  980.      */
  981.  
  982. STATIC VOID __regargs
  983. ResetMacroKeys(struct MacroKeys *Keys)
  984. {
  985.     STATIC STRPTR FunctionKeyCodes[4] =
  986.     {
  987.         "\\eOP",
  988.         "\\eOQ",
  989.         "\\eOR",
  990.         "\\eOS"
  991.     };
  992.  
  993.     WORD i;
  994.  
  995.     memset(Keys,0,sizeof(struct MacroKeys));
  996.  
  997.     for(i = 0 ; i < 4 ; i++)
  998.         strcpy(Keys -> Keys[1][i],FunctionKeyCodes[i]);
  999. }
  1000.  
  1001.     /* ScreenSizeStuff():
  1002.      *
  1003.      *    Set up the terminal screen size.
  1004.      */
  1005.  
  1006. VOID
  1007. ScreenSizeStuff()
  1008. {
  1009.     ObtainSemaphore(&TerminalSemaphore);
  1010.  
  1011.         /* Is this really the built-in emulation? */
  1012.  
  1013.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  1014.     {
  1015.         LONG    MaxColumns    = WindowWidth / TextFontWidth,
  1016.             MaxLines    = WindowHeight / TextFontHeight,
  1017.             Columns,
  1018.             Lines;
  1019.  
  1020.             /* Drop the text area marker. */
  1021.  
  1022.         if(Marking)
  1023.             DropMarker();
  1024.  
  1025.             /* Turn off the cursor. */
  1026.  
  1027.         ClearCursor();
  1028.  
  1029.             /* Set up the new screen width. */
  1030.  
  1031.         if(Config -> TerminalConfig -> NumColumns < 20)
  1032.             Columns = MaxColumns;
  1033.         else
  1034.             Columns = Config -> TerminalConfig -> NumColumns;
  1035.  
  1036.             /* Set up the new screen height. */
  1037.  
  1038.         if(Config -> TerminalConfig -> NumLines < 20)
  1039.             Lines = MaxLines;
  1040.         else
  1041.             Lines = Config -> TerminalConfig -> NumLines;
  1042.  
  1043.             /* More columns than we will be able to display? */
  1044.  
  1045.         if(Columns > MaxColumns)
  1046.             Columns = MaxColumns;
  1047.  
  1048.             /* More lines than we will be able to display? */
  1049.  
  1050.         if(Lines > MaxLines)
  1051.             Lines = MaxLines;
  1052.  
  1053.             /* Set up the central data. */
  1054.  
  1055.         LastColumn    = Columns - 1;
  1056.         LastLine    = Lines - 1;
  1057.         LastPixel    = MUL_X(Columns) - 1;
  1058.  
  1059.             /* Are we to clear the margin? */
  1060.  
  1061.         if(Columns < MaxColumns || Lines < MaxLines)
  1062.         {
  1063.                 /* Save the rendering attributes. */
  1064.  
  1065.             BackupRender();
  1066.  
  1067.                 /* Set the defaults. */
  1068.  
  1069.             SetAPen(RPort,BgPen = MappedPens[0][PenTable[0]]);
  1070.  
  1071.             SetMask(RPort,DepthMask);
  1072.  
  1073.                 /* Clear remaining columns. */
  1074.  
  1075.             if(Columns < MaxColumns)
  1076.                 ScrollLineRectFill(RPort,MUL_X(LastColumn + 1),0,WindowWidth - 1,WindowHeight - 1);
  1077.  
  1078.                 /* Clear remaining lines. */
  1079.  
  1080.             if(Lines < MaxLines)
  1081.                 ScrollLineRectFill(RPort,0,MUL_Y(LastLine + 1),WindowWidth - 1,WindowHeight - 1);
  1082.  
  1083.                 /* Restore rendering attributes. */
  1084.  
  1085.             BackupRender();
  1086.         }
  1087.  
  1088.             /* Truncate illegal cursor position. */
  1089.  
  1090.         if(CursorY > LastLine)
  1091.             CursorY = LastLine;
  1092.  
  1093.         ConFontScaleUpdate();
  1094.  
  1095.             /* Truncate illegal cursor position. */
  1096.  
  1097.         if(CursorX > LastPrintableColumn)
  1098.             CursorX = LastPrintableColumn;
  1099.  
  1100.             /* Fix scroll region button. */
  1101.  
  1102.         if(!RegionSet)
  1103.             Bottom = LastLine;
  1104.  
  1105.             /* Turn the cursor back on. */
  1106.  
  1107.         DrawCursor();
  1108.     }
  1109.  
  1110.     FixScreenSize = FALSE;
  1111.  
  1112.     ReleaseSemaphore(&TerminalSemaphore);
  1113. }
  1114.  
  1115.     /* PubScreenStuff():
  1116.      *
  1117.      *    This part handles the public screen setup stuff.
  1118.      */
  1119.  
  1120. VOID
  1121. PubScreenStuff()
  1122. {
  1123.     if(Screen)
  1124.     {
  1125.             /* Are we to make our screen public? */
  1126.  
  1127.         if(Config -> ScreenConfig -> MakeScreenPublic)
  1128.             PubScreenStatus(Screen,NULL);
  1129.         else
  1130.             PubScreenStatus(Screen,PSNF_PRIVATE);
  1131.  
  1132.             /* Are we to `shanghai' Workbench windows? */
  1133.  
  1134.         if(Config -> ScreenConfig -> ShanghaiWindows)
  1135.         {
  1136.             PublicModes |= SHANGHAI;
  1137.  
  1138.             SetPubScreenModes(PublicModes);
  1139.  
  1140.                 /* Make this the default public screen. */
  1141.  
  1142.             SetDefaultPubScreen(TermIDString);
  1143.         }
  1144.         else
  1145.         {
  1146.             PublicModes &= ~SHANGHAI;
  1147.  
  1148.             if(LockPubScreen(DefaultPubScreenName))
  1149.             {
  1150.                 SetDefaultPubScreen(DefaultPubScreenName);
  1151.  
  1152.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1153.             }
  1154.             else
  1155.                 SetDefaultPubScreen(NULL);
  1156.  
  1157.             SetPubScreenModes(PublicModes);
  1158.         }
  1159.     }
  1160.  
  1161.     FixPubScreenMode = FALSE;
  1162. }
  1163.  
  1164.     /* ConfigSetup():
  1165.      *
  1166.      *    Compare the current configuration with the
  1167.      *    last backup and reset the serial device, terminal,
  1168.      *    etc. if necessary.
  1169.      */
  1170.  
  1171. VOID
  1172. ConfigSetup()
  1173. {
  1174.     BYTE RasterWasEnabled = RasterEnabled;
  1175.  
  1176.         /* Hide or show the upload queue icon. */
  1177.  
  1178.     ToggleUploadQueueIcon(Config -> TransferConfig -> HideUploadIcon);
  1179.  
  1180.         /* Take care of the end-of-line translation. */
  1181.  
  1182.     Update_CR_LF_Translation();
  1183.  
  1184.         /* First we will take a look at the configuration
  1185.          * and try to find those parts which have changed
  1186.          * and require the main screen display to be
  1187.          * reopened.
  1188.          */
  1189.  
  1190.     if(PrivateConfig -> ScreenConfig -> FontHeight != Config -> ScreenConfig -> FontHeight)
  1191.         ResetDisplay = TRUE;
  1192.  
  1193.     if((PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL) || (PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL))
  1194.         ResetDisplay = TRUE;
  1195.  
  1196.     if(PrivateConfig -> ScreenConfig -> SplitStatus != Config -> ScreenConfig -> SplitStatus)
  1197.         ResetDisplay = TRUE;
  1198.  
  1199.     if(PrivateConfig -> ScreenConfig -> ShareScreen != Config -> ScreenConfig -> ShareScreen)
  1200.         ResetDisplay = TRUE;
  1201.  
  1202.     if(PrivateConfig -> ScreenConfig -> Depth != Config -> ScreenConfig -> Depth || PrivateConfig -> ScreenConfig -> OverscanType != Config -> ScreenConfig -> OverscanType)
  1203.         ResetDisplay = TRUE;
  1204.  
  1205.     if(PrivateConfig -> ScreenConfig -> DisplayWidth != Config -> ScreenConfig -> DisplayWidth || PrivateConfig -> ScreenConfig -> DisplayHeight != Config -> ScreenConfig -> DisplayHeight)
  1206.         ResetDisplay = TRUE;
  1207.  
  1208.     if(Stricmp(PrivateConfig -> ScreenConfig -> FontName,Config -> ScreenConfig -> FontName))
  1209.         ResetDisplay = TRUE;
  1210.  
  1211.     if(PrivateConfig -> TerminalConfig -> FontMode != Config -> TerminalConfig -> FontMode)
  1212.         ResetDisplay = TRUE;
  1213.  
  1214.     if(PrivateConfig -> TerminalConfig -> UseTerminalTask != Config -> TerminalConfig -> UseTerminalTask)
  1215.         ResetDisplay = TRUE;
  1216.  
  1217.     if(PrivateConfig -> TerminalConfig -> TextFontHeight != Config -> TerminalConfig -> TextFontHeight)
  1218.         ResetDisplay = TRUE;
  1219.  
  1220.     if(Stricmp(PrivateConfig -> TerminalConfig -> TextFontName,Config -> TerminalConfig -> TextFontName))
  1221.         ResetDisplay = TRUE;
  1222.  
  1223.     if(PrivateConfig -> ScreenConfig -> DisplayMode != Config -> ScreenConfig -> DisplayMode || PrivateConfig -> ScreenConfig -> ColourMode != Config -> ScreenConfig -> ColourMode)
  1224.         ResetDisplay = TRUE;
  1225.  
  1226.     if(PrivateConfig -> TerminalConfig -> IBMFontHeight != Config -> TerminalConfig -> IBMFontHeight)
  1227.         ResetDisplay = TRUE;
  1228.  
  1229.     if(Stricmp(PrivateConfig -> TerminalConfig -> IBMFontName,Config -> TerminalConfig -> IBMFontName))
  1230.         ResetDisplay = TRUE;
  1231.  
  1232.     if((PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode) && (PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_EIGHT || PrivateConfig -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  1233.     {
  1234.         if(PrivateConfig -> ScreenConfig -> Blinking != Config -> ScreenConfig -> Blinking)
  1235.             ResetDisplay = TRUE;
  1236.     }
  1237.  
  1238.     if(Kick30)
  1239.     {
  1240.         if(Config -> ScreenConfig -> UsePens != PrivateConfig -> ScreenConfig -> UsePens || memcmp(Config -> ScreenConfig -> PenArray,PrivateConfig -> ScreenConfig -> PenArray,sizeof(UWORD) * 12))
  1241.             ResetDisplay = TRUE;
  1242.     }
  1243.  
  1244.     if(Config -> ScreenConfig -> Depth != PrivateConfig -> ScreenConfig -> Depth)
  1245.         ResetDisplay = TRUE;
  1246.  
  1247.     if(PrivateConfig -> ScreenConfig -> FasterLayout != Config -> ScreenConfig -> FasterLayout)
  1248.         ResetDisplay = TRUE;
  1249.  
  1250.     if(PrivateConfig -> ScreenConfig -> StatusLine != Config -> ScreenConfig -> StatusLine)
  1251.         ResetDisplay = TRUE;
  1252.  
  1253.     if(PrivateConfig -> ScreenConfig -> TitleBar != Config -> ScreenConfig -> TitleBar)
  1254.         ResetDisplay = TRUE;
  1255.  
  1256.     if(PrivateConfig -> ScreenConfig -> UseWorkbench != Config -> ScreenConfig -> UseWorkbench)
  1257.         ResetDisplay = TRUE;
  1258.  
  1259.     if(strcmp(PrivateConfig -> ScreenConfig -> PubScreenName,Config -> ScreenConfig -> PubScreenName) && Config -> ScreenConfig -> UseWorkbench)
  1260.         ResetDisplay = TRUE;
  1261.  
  1262.     if(PrivateConfig -> EmulationConfig -> UseStandardPens != Config -> EmulationConfig -> UseStandardPens)
  1263.         ResetDisplay = TRUE;
  1264.  
  1265.     if(!Config -> EmulationConfig -> UseStandardPens && (memcmp(Config -> EmulationConfig -> Pens,PrivateConfig -> EmulationConfig -> Pens,sizeof(Config -> EmulationConfig -> Pens)) || memcmp(Config -> EmulationConfig -> Attributes,PrivateConfig -> EmulationConfig -> Attributes,sizeof(Config -> EmulationConfig -> Attributes))))
  1266.         ResetDisplay = TRUE;
  1267.  
  1268.         /* Now for the `harmless' actions which do not
  1269.          * require to change the screen or other
  1270.          * rendering data.
  1271.          */
  1272.  
  1273.     if(!ResetDisplay)
  1274.     {
  1275.         if(PrivateConfig -> TerminalConfig -> NumColumns != Config -> TerminalConfig -> NumColumns || PrivateConfig -> TerminalConfig -> NumLines != Config -> TerminalConfig -> NumLines)
  1276.         {
  1277.             if(Config -> ScreenConfig -> UseWorkbench)
  1278.             {
  1279.                 UWORD    Width,
  1280.                     Height;
  1281.  
  1282.                 if(Config -> TerminalConfig -> NumColumns < 20)
  1283.                     Width = ScreenWidth;
  1284.                 else
  1285.                     Width = Window -> BorderLeft + TextFontWidth * Config -> TerminalConfig -> NumColumns + Window -> BorderRight;
  1286.  
  1287.                 if(Config -> TerminalConfig -> NumLines < 20)
  1288.                     Height = ScreenHeight;
  1289.                 else
  1290.                     Height = Window -> BorderTop + TextFontHeight * Config -> TerminalConfig -> NumLines + Window -> BorderBottom;
  1291.  
  1292.                 ChangeWindowBox(Window,Window -> LeftEdge,Window -> TopEdge,Width,Height);
  1293.  
  1294.                 FixScreenSize = TRUE;
  1295.             }
  1296.             else
  1297.                 ResetDisplay = TRUE;
  1298.         }
  1299.     }
  1300.  
  1301.     if(PrivateConfig -> ScreenConfig -> MakeScreenPublic != Config -> ScreenConfig -> MakeScreenPublic || PrivateConfig -> ScreenConfig -> ShanghaiWindows != Config -> ScreenConfig -> ShanghaiWindows)
  1302.         PubScreenStuff();
  1303.  
  1304.     if(PrivateConfig -> ScreenConfig -> ColourMode == Config -> ScreenConfig -> ColourMode && (memcmp(PrivateConfig -> ScreenConfig -> Colours,Config -> ScreenConfig -> Colours,sizeof(UWORD) * 16) || memcmp(PrivateConfig -> ScreenConfig -> Colours96,Config -> ScreenConfig -> Colours96,sizeof(ColourEntry) * 16)))
  1305.         Current2DefaultPalette(Config);
  1306.  
  1307.         /* Are we to load a new transfer library? */
  1308.  
  1309.     if(Config -> TransferConfig -> DefaultType == XFER_XPR)
  1310.     {
  1311.         if(Config -> TransferConfig -> DefaultLibrary[0])
  1312.         {
  1313.             if(strcmp(PrivateConfig -> TransferConfig -> DefaultLibrary,Config -> TransferConfig -> DefaultLibrary))
  1314.             {
  1315.                 strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  1316.  
  1317.                 ProtocolSetup(FALSE);
  1318.             }
  1319.         }
  1320.         else
  1321.             CloseXPR();
  1322.     }
  1323.     else
  1324.     {
  1325.         CloseXPR();
  1326.  
  1327.         ProtocolSetup(FALSE);
  1328.     }
  1329.  
  1330.         /* No custom keymap this time? */
  1331.  
  1332.     if(!Config -> TerminalConfig -> KeyMapFileName[0])
  1333.     {
  1334.         KeyMap = NULL;
  1335.  
  1336.         if(KeySegment)
  1337.         {
  1338.             UnLoadSeg(KeySegment);
  1339.  
  1340.             KeySegment = NULL;
  1341.         }
  1342.     }
  1343.     else
  1344.     {
  1345.             /* Check whether the keymap name has changed. */
  1346.  
  1347.         if(strcmp(PrivateConfig -> TerminalConfig -> KeyMapFileName,Config -> TerminalConfig -> KeyMapFileName))
  1348.             KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  1349.     }
  1350.  
  1351.         /* Are we to load the keyboard macro settings? */
  1352.  
  1353.     if(Config -> MacroFileName[0] && Stricmp(PrivateConfig -> MacroFileName,Config -> MacroFileName))
  1354.     {
  1355.         if(!LoadMacros(Config -> MacroFileName,MacroKeys))
  1356.             ResetMacroKeys(MacroKeys);
  1357.         else
  1358.             strcpy(LastMacros,Config -> MacroFileName);
  1359.     }
  1360.  
  1361.         /* Are we to load the cursor key settings? */
  1362.  
  1363.     if(Config -> CursorFileName[0] && Stricmp(PrivateConfig -> CursorFileName,Config -> CursorFileName))
  1364.     {
  1365.         if(!ReadIFFData(Config -> CursorFileName,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  1366.             ResetCursorKeys(CursorKeys);
  1367.         else
  1368.             strcpy(LastCursorKeys,Config -> CursorFileName);
  1369.     }
  1370.  
  1371.         /* Are we to load the translation tables? */
  1372.  
  1373.     if(Config -> TranslationFileName[0] && Stricmp(PrivateConfig -> TranslationFileName,Config -> TranslationFileName))
  1374.     {
  1375.         if(SendTable)
  1376.         {
  1377.             FreeTranslationTable(SendTable);
  1378.  
  1379.             SendTable = NULL;
  1380.         }
  1381.  
  1382.         if(ReceiveTable)
  1383.         {
  1384.             FreeTranslationTable(ReceiveTable);
  1385.  
  1386.             ReceiveTable = NULL;
  1387.         }
  1388.  
  1389.         if(SendTable = AllocTranslationTable())
  1390.         {
  1391.             if(ReceiveTable = AllocTranslationTable())
  1392.             {
  1393.                 if(LoadTranslationTables(Config -> TranslationFileName,SendTable,ReceiveTable))
  1394.                 {
  1395.                     strcpy(LastTranslation,Config -> TranslationFileName);
  1396.  
  1397.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  1398.                     {
  1399.                         FreeTranslationTable(SendTable);
  1400.  
  1401.                         SendTable = NULL;
  1402.  
  1403.                         FreeTranslationTable(ReceiveTable);
  1404.  
  1405.                         ReceiveTable = NULL;
  1406.                     }
  1407.                 }
  1408.                 else
  1409.                 {
  1410.                     FreeTranslationTable(SendTable);
  1411.  
  1412.                     SendTable = NULL;
  1413.  
  1414.                     FreeTranslationTable(ReceiveTable);
  1415.  
  1416.                     ReceiveTable = NULL;
  1417.                 }
  1418.             }
  1419.             else
  1420.             {
  1421.                 FreeTranslationTable(SendTable);
  1422.  
  1423.                 SendTable = NULL;
  1424.             }
  1425.         }
  1426.     }
  1427.  
  1428.         /* Update the text sending functions. */
  1429.  
  1430.     SendSetup();
  1431.  
  1432.         /* Are we to load the fast macro settings? */
  1433.  
  1434.     if(Config -> FastMacroFileName[0] && Stricmp(PrivateConfig -> FastMacroFileName,Config -> FastMacroFileName))
  1435.     {
  1436.         if(FastWindow)
  1437.             LT_LockWindow(FastWindow);
  1438.  
  1439.         FreeList(&FastMacroList);
  1440.  
  1441.         if(LoadFastMacros(Config -> FastMacroFileName,&FastMacroList))
  1442.             strcpy(LastFastMacros,Config -> FastMacroFileName);
  1443.  
  1444.         if(FastWindow)
  1445.         {
  1446.             RefreshFastWindow(TRUE);
  1447.  
  1448.             LT_UnlockWindow(FastWindow);
  1449.         }
  1450.     }
  1451.  
  1452.         /* Serial configuration needs updating? */
  1453.  
  1454.     ReconfigureSerial(Window,NULL);
  1455.  
  1456.         /* Are we to open the fast macro panel? */
  1457.  
  1458.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  1459.         HadFastMacros = TRUE;
  1460.  
  1461.         /* Are we to freeze the text buffer? */
  1462.  
  1463.     if(!Config -> CaptureConfig -> BufferEnabled)
  1464.         BufferFrozen = TRUE;
  1465.  
  1466.         /* Now for the actions which require that the
  1467.          * screen stays open.
  1468.          */
  1469.  
  1470.     if(!ResetDisplay)
  1471.     {
  1472.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1473.         {
  1474.             if(PrivateConfig -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL || (Config -> TerminalConfig -> EmulationFileName[0] && strcmp(PrivateConfig -> TerminalConfig -> EmulationFileName,Config -> TerminalConfig -> EmulationFileName)))
  1475.             {
  1476.                 if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  1477.                 {
  1478.                     Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  1479.  
  1480.                     ResetDisplay = TRUE;
  1481.  
  1482.                     RasterEnabled = TRUE;
  1483.  
  1484.                     MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Config -> TerminalConfig -> EmulationFileName);
  1485.                 }
  1486.                 else
  1487.                     RasterEnabled = FALSE;
  1488.             }
  1489.         }
  1490.         else
  1491.         {
  1492.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1493.             {
  1494.                 XEmulatorClearConsole(XEM_IO);
  1495.  
  1496.                 CloseEmulator();
  1497.  
  1498.                 RasterEnabled = TRUE;
  1499.  
  1500.                 ClearCursor();
  1501.  
  1502.                 Reset();
  1503.  
  1504.                 DrawCursor();
  1505.             }
  1506.             else
  1507.                 RasterEnabled = TRUE;
  1508.         }
  1509.  
  1510.         if(RasterEnabled != RasterWasEnabled)
  1511.             RasterEraseScreen(2);
  1512.  
  1513.         if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  1514.         {
  1515.             PaletteSetup(Config);
  1516.  
  1517.             LoadColourTable(VPort,NormalColourTable,NormalColours,PaletteSize);
  1518.         }
  1519.  
  1520.         if(Config -> MiscConfig -> OpenFastMacroPanel && !FastWindow)
  1521.             OpenFastWindow();
  1522.  
  1523.         PubScreenStuff();
  1524.  
  1525.         if(Menu)
  1526.         {
  1527.             CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  1528.  
  1529.             if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  1530.                 OffItem(MEN_CHAT_LINE);
  1531.             else
  1532.                 CheckItem(MEN_CHAT_LINE,ChatMode);
  1533.  
  1534.             SetTransferMenu(TRUE);
  1535.  
  1536.             SetRasterMenu(RasterEnabled);
  1537.  
  1538.             if(MatrixWindow)
  1539.                 CheckItem(MEN_MATRIX_WINDOW,TRUE);
  1540.  
  1541.             if(InfoWindow)
  1542.                 CheckItem(MEN_STATUS_WINDOW,TRUE);
  1543.  
  1544.             if(PacketWindow)
  1545.                 CheckItem(MEN_PACKET_WINDOW,TRUE);
  1546.  
  1547.             if(ChatMode)
  1548.                 CheckItem(MEN_CHAT_LINE,TRUE);
  1549.  
  1550.             if(FastWindow)
  1551.                 CheckItem(MEN_FAST_MACROS_WINDOW,TRUE);
  1552.  
  1553. //            if(TransferProcess)
  1554. //                CheckItem(MEN_UPLOAD_QUEUE_WINDOW,TRUE);
  1555.  
  1556.                 /* Disable the dialing functions if online. */
  1557.  
  1558.             ObtainSemaphore(&OnlineSemaphore);
  1559.  
  1560.             if(Online)
  1561.                 SetDialMenu(FALSE);
  1562.             else
  1563.                 SetDialMenu(TRUE);
  1564.  
  1565.             ReleaseSemaphore(&OnlineSemaphore);
  1566.         }
  1567.  
  1568.         Blocking = FALSE;
  1569.     }
  1570.     else
  1571.     {
  1572.             /* Are we no longer to use the external emulator? */
  1573.  
  1574.         if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  1575.         {
  1576.             if(XEmulatorBase && PrivateConfig -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  1577.             {
  1578.                 XEmulatorClearConsole(XEM_IO);
  1579.  
  1580.                 CloseEmulator();
  1581.             }
  1582.         }
  1583.  
  1584.         RasterEnabled = TRUE;
  1585.     }
  1586.  
  1587.         /* Change the task priority. */
  1588.  
  1589.     SetTaskPri(ThisProcess,(LONG)Config -> MiscConfig -> Priority);
  1590.  
  1591.     ConOutputUpdate();
  1592.  
  1593.     ConFontScaleUpdate();
  1594.  
  1595.     ConProcessUpdate();
  1596.  
  1597.         /* Reset the scanner. */
  1598.  
  1599.     FlowInit(TRUE);
  1600. }
  1601.  
  1602.     /* DisplayReset():
  1603.      *
  1604.      *    Reset the entire display if necessary.
  1605.      */
  1606.  
  1607. BYTE
  1608. DisplayReset()
  1609. {
  1610.     UBYTE    *Result;
  1611.     BYTE     Success = TRUE;
  1612.  
  1613.         /* Delete the display (if possible).
  1614.          * This will go wrong if there
  1615.          * are any visitor windows on our
  1616.          * screen.
  1617.          */
  1618.  
  1619.     if(DeleteDisplay())
  1620.     {
  1621.         if(Result = CreateDisplay(FALSE))
  1622.         {
  1623.             DeleteDisplay();
  1624.  
  1625.             MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Result);
  1626.  
  1627.             Success = FALSE;
  1628.         }
  1629.         else
  1630.         {
  1631.             BumpWindow(Window);
  1632.  
  1633.             PubScreenStuff();
  1634.  
  1635.             DisplayReopened = TRUE;
  1636.         }
  1637.     }
  1638.     else
  1639.     {
  1640.         SaveConfig(PrivateConfig,Config);
  1641.  
  1642.         BlockWindows();
  1643.  
  1644.         MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),LocaleString(MSG_TERMMAIN_CANNOT_CLOSE_SCREEN_YET_TXT));
  1645.  
  1646.         ReleaseWindows();
  1647.  
  1648.         Success = TRUE;
  1649.     }
  1650.  
  1651.     ResetDisplay = FALSE;
  1652.  
  1653.         /* Prepare for the worst case... */
  1654.  
  1655.     if(Success)
  1656.         Apocalypse = FALSE;
  1657.     else
  1658.         MainTerminated = Apocalypse = TRUE;
  1659.  
  1660.     return(Success);
  1661. }
  1662.  
  1663.     /* DeleteDisplay():
  1664.      *
  1665.      *    Free all resources associated with the terminal
  1666.      *    display (tasks, interrupts, screen, window, etc.).
  1667.      */
  1668.  
  1669. BYTE
  1670. DeleteDisplay()
  1671. {
  1672.     struct Screen *WhichScreen;
  1673.  
  1674.     if(SharedScreen)
  1675.         WhichScreen = SharedScreen;
  1676.     else
  1677.         WhichScreen = Screen;
  1678.  
  1679.     if(WhichScreen)
  1680.     {
  1681.         if(!(PubScreenStatus(WhichScreen,PSNF_PRIVATE) & PSNF_PRIVATE))
  1682.             return(FALSE);
  1683.     }
  1684.  
  1685.     GuideCleanup();
  1686.  
  1687.     DeleteLED();
  1688.  
  1689.     CloseQueueWindow();
  1690.  
  1691.     if(StatusProcess)
  1692.     {
  1693.         Forbid();
  1694.  
  1695.         Signal(StatusProcess,SIG_KILL);
  1696.  
  1697.         ClrSignal(SIG_HANDSHAKE);
  1698.  
  1699.         Wait(SIG_HANDSHAKE);
  1700.  
  1701.         Permit();
  1702.  
  1703.         StatusProcess = NULL;
  1704.     }
  1705.  
  1706.     if(Marking)
  1707.         FreeMarker();
  1708.  
  1709.     FirstClick    = TRUE;
  1710.     HoldClick    = FALSE;
  1711.  
  1712.     CloseInfoWindow();
  1713.  
  1714.     DeleteReview();
  1715.  
  1716.     DeleteEmulationProcess();
  1717.  
  1718.     if(Config)
  1719.     {
  1720.         if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && XEmulatorBase)
  1721.             CloseEmulator();
  1722.     }
  1723.  
  1724.     DeleteRaster();
  1725.  
  1726.     DeleteScale();
  1727.  
  1728.     if(TabStops)
  1729.     {
  1730.         FreeVecPooled(TabStops);
  1731.  
  1732.         TabStops = NULL;
  1733.     }
  1734.  
  1735.     if(ScrollLines)
  1736.     {
  1737.         FreeVecPooled(ScrollLines);
  1738.  
  1739.         ScrollLines = NULL;
  1740.     }
  1741.  
  1742.     if(Screen)
  1743.         ScreenToBack(Screen);
  1744.  
  1745.     if(FastWindow)
  1746.     {
  1747.         HadFastMacros = TRUE;
  1748.  
  1749.         CloseFastWindow();
  1750.     }
  1751.     else
  1752.         HadFastMacros = FALSE;
  1753.  
  1754.     if(MatrixWindow)
  1755.         CloseMatrixWindow();
  1756.  
  1757.         /* Clean up the menu glyphs. */
  1758.  
  1759.     DisposeObject(AmigaGlyph);
  1760.  
  1761.     AmigaGlyph = NULL;
  1762.  
  1763.     DisposeObject(CheckGlyph);
  1764.  
  1765.     CheckGlyph = NULL;
  1766.  
  1767.     if(StatusWindow)
  1768.     {
  1769.         ClearMenuStrip(StatusWindow);
  1770.         CloseWindowSafely(StatusWindow);
  1771.  
  1772.         StatusWindow = NULL;
  1773.     }
  1774.  
  1775.     if(DefaultPubScreen)
  1776.     {
  1777.         UnlockPubScreen(NULL,DefaultPubScreen);
  1778.  
  1779.         DefaultPubScreen = NULL;
  1780.     }
  1781.  
  1782.         /* Remove AppWindow link. */
  1783.  
  1784.     if(WorkbenchWindow)
  1785.     {
  1786.         RemoveAppWindow(WorkbenchWindow);
  1787.  
  1788.         WorkbenchWindow = NULL;
  1789.     }
  1790.  
  1791.         /* Remove AppWindow port and any pending messages. */
  1792.  
  1793.     if(WorkbenchPort)
  1794.     {
  1795.         struct Message *Message;
  1796.  
  1797.         while(Message = GetMsg(WorkbenchPort))
  1798.             ReplyMsg(Message);
  1799.  
  1800.         DeleteMsgPort(WorkbenchPort);
  1801.  
  1802.         WorkbenchPort = NULL;
  1803.     }
  1804.  
  1805.     if(DrawInfo)
  1806.     {
  1807.             /* Release the rendering pens. */
  1808.  
  1809.         FreeScreenDrawInfo(Window -> WScreen,DrawInfo);
  1810.  
  1811.         DrawInfo = NULL;
  1812.     }
  1813.  
  1814.     HideChatGadget();
  1815.  
  1816.     if(Window)
  1817.     {
  1818.         if(!Screen)
  1819.             PutWindowInfo(WINDOW_MAIN,Window -> LeftEdge,Window -> TopEdge,Window -> Width,Window -> Height);
  1820.  
  1821.         if(AllocatedPens && Kick30)
  1822.         {
  1823.             WORD i;
  1824.  
  1825.             ObtainSemaphore(&TerminalSemaphore);
  1826.  
  1827.                 /* Erase the window contents. We will
  1828.                  * want to release any pens we have
  1829.                  * allocated and want to avoid nasty
  1830.                  * flashing and flickering.
  1831.                  */
  1832.  
  1833.             SetAPen(RPort,0);
  1834.  
  1835.             RectFill(RPort,WindowLeft,WindowTop,WindowLeft + WindowWidth - 1,WindowTop + WindowHeight - 1);
  1836.  
  1837.                 /* Release any pens we have allocated. */
  1838.  
  1839.             for(i = 0 ; i < 32 ; i++)
  1840.             {
  1841.                 if(MappedPens[1][i])
  1842.                 {
  1843.                     ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  1844.  
  1845.                     MappedPens[0][i] = i;
  1846.                     MappedPens[1][i] = FALSE;
  1847.                 }
  1848.             }
  1849.  
  1850.             AllocatedPens = FALSE;
  1851.  
  1852.             ReleaseSemaphore(&TerminalSemaphore);
  1853.         }
  1854.  
  1855.         if(ClipRegion)
  1856.         {
  1857.             InstallClipRegion(Window -> WLayer,OldRegion);
  1858.  
  1859.             DisposeRegion(ClipRegion);
  1860.  
  1861.             ClipRegion = NULL;
  1862.         }
  1863.  
  1864.         ClearMenuStrip(Window);
  1865.  
  1866.         ThisProcess -> pr_WindowPtr = OldWindowPtr;
  1867.  
  1868.         PopWindow();
  1869.  
  1870.         if(TermPort)
  1871.             TermPort -> TopWindow = NULL;
  1872.  
  1873.         LT_DeleteWindowLock(Window);
  1874.  
  1875.         CloseWindow(Window);
  1876.  
  1877.         Window = NULL;
  1878.     }
  1879.  
  1880.     if(Menu)
  1881.     {
  1882.         LT_DisposeMenu(Menu);
  1883.         Menu = NULL;
  1884.     }
  1885.  
  1886.     if(VisualInfo)
  1887.     {
  1888.         FreeVisualInfo(VisualInfo);
  1889.  
  1890.         VisualInfo = NULL;
  1891.     }
  1892.  
  1893.     DeletePacketWindow(FALSE);
  1894.  
  1895.     if(UserTextFont)
  1896.     {
  1897.         CloseFont(UserTextFont);
  1898.  
  1899.         UserTextFont = NULL;
  1900.     }
  1901.  
  1902.         /* Before we can close screen we will have to
  1903.          * make sure that it is no longer the default
  1904.          * public screen.
  1905.          */
  1906.  
  1907.     if(Config)
  1908.     {
  1909.         if(Config -> ScreenConfig -> ShanghaiWindows)
  1910.         {
  1911.             if(LockPubScreen(DefaultPubScreenName))
  1912.             {
  1913.                 SetDefaultPubScreen(DefaultPubScreenName);
  1914.  
  1915.                 UnlockPubScreen(DefaultPubScreenName,NULL);
  1916.             }
  1917.             else
  1918.                 SetDefaultPubScreen(NULL);
  1919.         }
  1920.     }
  1921.  
  1922.     if(Screen)
  1923.     {
  1924.         CloseScreen(Screen);
  1925.  
  1926.         Screen = NULL;
  1927.     }
  1928.  
  1929.     if(SharedScreen)
  1930.     {
  1931.         CloseScreen(SharedScreen);
  1932.  
  1933.         SharedScreen = NULL;
  1934.     }
  1935.  
  1936.     if(GFX)
  1937.     {
  1938.         CloseFont(GFX);
  1939.  
  1940.         GFX = NULL;
  1941.     }
  1942.  
  1943.     if(TextFont)
  1944.     {
  1945.         CloseFont(TextFont);
  1946.  
  1947.         TextFont = NULL;
  1948.     }
  1949.  
  1950.     return(TRUE);
  1951. }
  1952.  
  1953. STATIC VOID __regargs
  1954. StatusSizeSetup(struct Screen *Screen,LONG *StatusWidth,LONG *StatusHeight)
  1955. {
  1956.     SZ_SizeSetup(Screen,&UserFont);
  1957.  
  1958.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0] && Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  1959.     {
  1960.         *StatusHeight = 0;
  1961.  
  1962.         return;
  1963.     }
  1964.  
  1965.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  1966.     {
  1967.         if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  1968.         {
  1969.             *StatusWidth    = 80 * UserFontWidth;
  1970.             *StatusHeight    = UserFontHeight;
  1971.  
  1972.             if(Config -> ScreenConfig -> SplitStatus)
  1973.             {
  1974.                 *StatusWidth    += 2;
  1975.                 *StatusHeight    += 2;
  1976.             }
  1977.         }
  1978.         else
  1979.         {
  1980.             LONG    i,Len,Max;
  1981.             UWORD    ColumnLeft[4],
  1982.                 ColumnWidth[4];
  1983.  
  1984.             *StatusWidth    = 2;
  1985.             *StatusHeight    = SZ_BoxHeight(2);
  1986.  
  1987.             ColumnLeft[0] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_STATUS_TXT,MSG_TERMSTATUSDISPLAY_FONT_TXT,-1);
  1988.             ColumnLeft[1] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_PROTOCOL_TXT,MSG_TERMSTATUSDISPLAY_TERMINAL_TXT,-1);
  1989.             ColumnLeft[2] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_BAUDRATE_TXT,MSG_TERMSTATUSDISPLAY_PARAMETERS_TXT,-1);
  1990.             ColumnLeft[3] = SZ_LeftOffsetN(MSG_TERMSTATUSDISPLAY_TIME_TXT,MSG_TERMSTATUSDISPLAY_ONLINE_TXT,-1);
  1991.  
  1992.             Max = 0;
  1993.  
  1994.             for(i = MSG_TERMAUX_READY_TXT ; i <= MSG_TERMAUX_HANG_UP_TXT ; i++)
  1995.             {
  1996.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  1997.                     Max = Len;
  1998.             }
  1999.  
  2000.             for(i = MSG_TERMSTATUSDISPLAY_FROZEN_TXT ; i <= MSG_TERMSTATUSDISPLAY_RECORDING_TXT ; i++)
  2001.             {
  2002.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  2003.                     Max = Len;
  2004.             }
  2005.  
  2006.             ColumnWidth[0] = Max;
  2007.  
  2008.             Max = SZ_BoxWidth(12);
  2009.  
  2010.             for(i = MSG_TERMAUX_ANSI_VT102_TXT ; i <= MSG_TERMAUX_HEX_TXT ; i++)
  2011.             {
  2012.                 if((Len = SZ_BoxWidth(strlen(LocaleString(i)))) > Max)
  2013.                     Max = Len;
  2014.             }
  2015.  
  2016.             ColumnWidth[1] = Max;
  2017.  
  2018.             Max = SZ_BoxWidth(10);
  2019.  
  2020.             for(i = MSG_TERMAUX_NONE_TXT ; i <= MSG_TERMAUX_SPACE_TXT ; i++)
  2021.             {
  2022.                 if((Len = SZ_BoxWidth(4 + strlen(LocaleString(i)))) > Max)
  2023.                     Max = Len;
  2024.             }
  2025.  
  2026.             ColumnWidth[2] = Max;
  2027.  
  2028.             ColumnWidth[3] = SZ_BoxWidth(8);
  2029.  
  2030.             for(i = 0 ; i < 4 ; i++)
  2031.                 *StatusWidth += ColumnWidth[i] + ColumnLeft[i];
  2032.  
  2033.             *StatusWidth += 3 * InterWidth;
  2034.  
  2035.             if(!Config -> ScreenConfig -> SplitStatus)
  2036.             {
  2037.                 *StatusWidth    += 2;
  2038.                 *StatusHeight    += 4;
  2039.             }
  2040.             else
  2041.             {
  2042.                 *StatusWidth    += 2;
  2043.                 *StatusHeight    += 2;
  2044.             }
  2045.         }
  2046.     }
  2047.     else
  2048.         *StatusHeight = 0;
  2049. }
  2050.  
  2051.     /* CreateDisplay(BYTE FirstSetup):
  2052.      *
  2053.      *    Open the display and allocate associated data.
  2054.      */
  2055.  
  2056. STRPTR __regargs
  2057. CreateDisplay(BYTE FirstSetup)
  2058. {
  2059.     UWORD            Count = 0,i;
  2060.     LONG            ErrorCode,Top,Height;
  2061.     ULONG            TagArray[9];
  2062.     struct Rectangle    DisplayClip;
  2063.     BYTE            OpenFailed = FALSE,
  2064.                 RealDepth;
  2065.     ULONG            X_DPI,Y_DPI;
  2066.     UWORD            PenArray[16];
  2067.     LONG            StatusWidth,
  2068.                 StatusHeight;
  2069.  
  2070.     BlockNestCount = 0;
  2071.  
  2072.     WeAreBlocking = FALSE;
  2073.  
  2074.     SetQueueDiscard(SpecialQueue,FALSE);
  2075.  
  2076.     TagDPI[0] . ti_Tag = TAG_DONE;
  2077.  
  2078.         /* Don't permit weird settings. */
  2079.  
  2080.     if(!Config -> ScreenConfig -> StatusLine || (!Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench))
  2081.         Config -> ScreenConfig -> SplitStatus = FALSE;
  2082.  
  2083.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  2084.     {
  2085.         STRPTR ScreenName = NULL;
  2086.  
  2087.         if(Config -> ScreenConfig -> PubScreenName[0])
  2088.         {
  2089.             struct Screen *SomeScreen;
  2090.  
  2091.             if(SomeScreen = LockPubScreen(Config -> ScreenConfig -> PubScreenName))
  2092.             {
  2093.                 UnlockPubScreen(NULL,SomeScreen);
  2094.  
  2095.                 ScreenName = Config -> ScreenConfig -> PubScreenName;
  2096.             }
  2097.         }
  2098.  
  2099.         if(!(DefaultPubScreen = LockPubScreen(ScreenName)))
  2100.             return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_DEFAULT_PUBLIC_SCREEN_TXT));
  2101.         else
  2102.         {
  2103.             GetDPI(GetVPModeID(&DefaultPubScreen -> ViewPort),&X_DPI,&Y_DPI);
  2104.  
  2105.             strcpy(UserFontName,DefaultPubScreen -> Font -> ta_Name);
  2106.  
  2107.             UserFont . tta_Name    = UserFontName;
  2108.             UserFont . tta_YSize    = DefaultPubScreen -> Font -> ta_YSize;
  2109.             UserFont . tta_Style    = DefaultPubScreen -> Font -> ta_Style;
  2110.             UserFont . tta_Flags    = DefaultPubScreen -> Font -> ta_Flags;
  2111.         }
  2112.     }
  2113.  
  2114.     if(!Config -> ScreenConfig -> UseWorkbench)
  2115.     {
  2116.         GetDPI(Config -> ScreenConfig -> DisplayMode,&X_DPI,&Y_DPI);
  2117.  
  2118.         strcpy(UserFontName,Config -> ScreenConfig -> FontName);
  2119.  
  2120.         UserFont . tta_Name    = UserFontName;
  2121.         UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  2122.         UserFont . tta_Style    = FS_NORMAL | FSF_TAGGED;
  2123.         UserFont . tta_Flags    = FPF_DESIGNED;
  2124.         UserFont . tta_Tags    = TagDPI;
  2125.  
  2126.         TagDPI[0] . ti_Tag     = TA_DeviceDPI;
  2127.         TagDPI[0] . ti_Data     = (X_DPI << 16) | Y_DPI;
  2128.         TagDPI[1] . ti_Tag     = TAG_DONE;
  2129.     }
  2130.  
  2131.     if(!(UserTextFont = OpenDiskFont(&UserFont)))
  2132.     {
  2133.         if(Config -> ScreenConfig -> UseWorkbench)
  2134.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  2135.         else
  2136.         {
  2137.             strcpy(Config -> ScreenConfig -> FontName,    "topaz.font");
  2138.             strcpy(UserFontName,                "topaz.font");
  2139.  
  2140.             Config -> ScreenConfig -> FontHeight = 8;
  2141.  
  2142.             UserFont . tta_YSize    = Config -> ScreenConfig -> FontHeight;
  2143.             UserFont . tta_Style    = FS_NORMAL;
  2144.             UserFont . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  2145.  
  2146.             if(!(UserTextFont = OpenFont(&UserFont)))
  2147.                 return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_FONT_TXT));
  2148.         }
  2149.     }
  2150.  
  2151. Reopen:    if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  2152.     {
  2153.         strcpy(TextFontName,Config -> TerminalConfig -> IBMFontName);
  2154.  
  2155.         TextAttr . tta_YSize = Config -> TerminalConfig -> IBMFontHeight;
  2156.     }
  2157.     else
  2158.     {
  2159.         strcpy(TextFontName,Config -> TerminalConfig -> TextFontName);
  2160.  
  2161.         TextAttr . tta_YSize = Config -> TerminalConfig -> TextFontHeight;
  2162.     }
  2163.  
  2164.     TextAttr . tta_Name    = TextFontName;
  2165.     TextAttr . tta_Style    = FS_NORMAL | FSF_TAGGED;
  2166.     TextAttr . tta_Flags    = FPF_DESIGNED;
  2167.     TextAttr . tta_Tags    = TagDPI;
  2168.  
  2169.     if(!(TextFont = OpenDiskFont(&TextAttr)))
  2170.     {
  2171.         if(Config -> TerminalConfig -> FontMode != FONT_STANDARD)
  2172.         {
  2173.             Config -> TerminalConfig -> FontMode = FONT_STANDARD;
  2174.  
  2175.             goto Reopen;
  2176.         }
  2177.  
  2178.         strcpy(Config -> TerminalConfig -> TextFontName,    "topaz.font");
  2179.         strcpy(TextFontName,                    "topaz.font");
  2180.  
  2181.         Config -> TerminalConfig -> TextFontHeight = 8;
  2182.  
  2183.         TextAttr . tta_YSize    = Config -> TerminalConfig -> TextFontHeight;
  2184.         TextAttr . tta_Style    = FS_NORMAL;
  2185.         TextAttr . tta_Flags    = FPF_DESIGNED | FPF_ROMFONT;
  2186.         TextAttr . tta_Tags    = NULL;
  2187.  
  2188.         if(!(TextFont = OpenFont(&TextAttr)))
  2189.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_OPEN_TEXT_TXT));
  2190.     }
  2191.  
  2192.     TextFontHeight    = TextFont -> tf_YSize;
  2193.     TextFontWidth    = TextFont -> tf_XSize;
  2194.     TextFontBase    = TextFont -> tf_Baseline;
  2195.  
  2196.         /* Determine extra font box width for slanted/boldface glyphs. */
  2197.  
  2198.     FontRightExtend    = MAX(TextFont -> tf_XSize / 2,TextFont -> tf_BoldSmear);
  2199.  
  2200.     CurrentFont = TextFont;
  2201.  
  2202.     GFXFont . ta_YSize = TextFontHeight;
  2203.  
  2204.     if(GFX = (struct TextFont *)OpenDiskFont(&GFXFont))
  2205.     {
  2206.         if(GFX -> tf_XSize != TextFont -> tf_XSize || GFX -> tf_YSize != TextFont -> tf_YSize)
  2207.         {
  2208.             CloseFont(GFX);
  2209.  
  2210.             GFX = NULL;
  2211.         }
  2212.     }
  2213.  
  2214.     UserFontHeight    = UserTextFont -> tf_YSize;
  2215.     UserFontWidth    = UserTextFont -> tf_XSize;
  2216.     UserFontBase    = UserTextFont -> tf_Baseline;
  2217.  
  2218.     if(Config -> ScreenConfig -> UseWorkbench || Config -> ScreenConfig -> ShareScreen)
  2219.     {
  2220.         struct TagItem     SomeTags[7];
  2221.         LONG         FullWidth,
  2222.                  Height,Width,
  2223.                  Index = 0;
  2224.         struct Screen    *LocalScreen = DefaultPubScreen;
  2225.  
  2226.         if(Config -> ScreenConfig -> ShareScreen && !Config -> ScreenConfig -> UseWorkbench)
  2227.         {
  2228.             struct DimensionInfo DimensionInfo;
  2229.  
  2230.             if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2231.             {
  2232.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&DefaultPubScreen -> ViewPort);
  2233.  
  2234.                 if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2235.                 {
  2236.                     LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2237.                         Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2238.  
  2239.                     if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2240.                         Config -> ScreenConfig -> DisplayWidth = Width;
  2241.  
  2242.                     if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2243.                         Config -> ScreenConfig -> DisplayHeight = Height;
  2244.                 }
  2245.             }
  2246.  
  2247.             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2248.             {
  2249.                 LONG    Depth,ScreenWidth,ScreenHeight;
  2250.                 UWORD    Pens = (UWORD)~0;
  2251.  
  2252.                 if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight && AslBase -> lib_Version >= 38)
  2253.                 {
  2254.                     ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2255.                     ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2256.                 }
  2257.                 else
  2258.                 {
  2259.                     ScreenWidth    = 0;
  2260.                     ScreenHeight    = 0;
  2261.                 }
  2262.  
  2263.                 switch(Config -> ScreenConfig -> ColourMode)
  2264.                 {
  2265.                     case COLOUR_EIGHT:
  2266.  
  2267.                         Depth = 3;
  2268.                         break;
  2269.  
  2270.                     case COLOUR_SIXTEEN:
  2271.  
  2272.                         Depth = 4;
  2273.                         break;
  2274.  
  2275.                     case COLOUR_AMIGA:
  2276.  
  2277.                         Depth = 2;
  2278.                         break;
  2279.  
  2280.                     default:
  2281.  
  2282.                         Depth = 1;
  2283.                         break;
  2284.                 }
  2285.  
  2286.                 if(Depth > DimensionInfo . MaxDepth)
  2287.                     Depth = DimensionInfo . MaxDepth;
  2288.  
  2289.                 if(!Kick30 && Depth > 2)
  2290.                     Depth = 2;
  2291.  
  2292.                 if(Config -> ScreenConfig -> Depth && Config -> ScreenConfig -> Depth <= DimensionInfo . MaxDepth)
  2293.                     Depth = Config -> ScreenConfig -> Depth;
  2294.  
  2295. #if defined(_M68030)
  2296.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2297. #endif
  2298.  
  2299. #if defined(_M68040)
  2300.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'040 ",TermDate,TermIDString);
  2301. #endif
  2302.  
  2303. #if !defined(_M68030) && !defined(_M68040)
  2304.                 SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  2305. #endif    /* _M68030 */
  2306.  
  2307.                 StatusSizeSetup(NULL,&StatusWidth,&StatusHeight);
  2308.  
  2309.                 if(StatusHeight && StatusWidth > ScreenWidth)
  2310.                     ScreenWidth = StatusWidth;
  2311.  
  2312.                 if(SharedScreen = OpenScreenTags(NULL,
  2313.                     ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  2314.                     ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  2315.  
  2316.                     SA_Title,    ScreenTitle,
  2317.                     SA_Depth,    Depth,
  2318.                     SA_Pens,    &Pens,
  2319.                     SA_Overscan,    AslBase -> lib_Version >= 38 ? Config -> ScreenConfig -> OverscanType : OSCAN_TEXT,
  2320.                     SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  2321.                     SA_Font,    &UserFont,
  2322.                     SA_AutoScroll,    TRUE,
  2323.                     SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  2324.                     SA_PubName,    TermIDString,
  2325.                     SA_Interleaved,    Config -> ScreenConfig -> FasterLayout,
  2326.                     SA_SharePens,    TRUE,
  2327.                 TAG_DONE))
  2328.                 {
  2329.                     LocalScreen = SharedScreen;
  2330.  
  2331.                     if(DefaultPubScreen)
  2332.                     {
  2333.                         UnlockPubScreen(NULL,DefaultPubScreen);
  2334.  
  2335.                         DefaultPubScreen = NULL;
  2336.                     }
  2337.  
  2338.                     if(Config -> ScreenConfig -> MakeScreenPublic)
  2339.                         PubScreenStatus(LocalScreen,NULL);
  2340.                     else
  2341.                         PubScreenStatus(LocalScreen,PSNF_PRIVATE);
  2342.                 }
  2343.             }
  2344.         }
  2345.  
  2346.         if(!SharedScreen)
  2347.         {
  2348. #if defined(_M68030)
  2349.             SPrintf(ScreenTitle,"%s '030 (%s)",TermName,TermDate);
  2350. #endif
  2351.  
  2352. #if defined(_M68040)
  2353.             SPrintf(ScreenTitle,"%s '040 (%s)",TermName,TermDate);
  2354. #endif
  2355.  
  2356. #if !defined(_M68030) && !defined(_M68040)
  2357.             SPrintf(ScreenTitle,"%s (%s)",TermName,TermDate);
  2358. #endif
  2359.         }
  2360.  
  2361.         StatusSizeSetup(LocalScreen,&StatusWidth,&StatusHeight);
  2362.  
  2363.         if(GetBitMapDepth(LocalScreen -> RastPort . BitMap) == 1 || Config -> ScreenConfig -> FasterLayout)
  2364.             UseMasking = FALSE;
  2365.         else
  2366.         {
  2367.             if(Kick30)
  2368.             {
  2369.                 if(GetBitMapAttr(LocalScreen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  2370.                     UseMasking = FALSE;
  2371.                 else
  2372.                     UseMasking = TRUE;
  2373.             }
  2374.             else
  2375.                 UseMasking = TRUE;
  2376.         }
  2377.  
  2378.         VPort = &LocalScreen -> ViewPort;
  2379.  
  2380.             /* Get the current display dimensions. */
  2381.  
  2382.         if(VPort -> ColorMap -> cm_vpe)
  2383.         {
  2384.             struct ViewPortExtra *Extra;
  2385.  
  2386.             Extra = VPort -> ColorMap -> cm_vpe;
  2387.  
  2388.             ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2389.             ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2390.         }
  2391.         else
  2392.         {
  2393.             struct ViewPortExtra *Extra;
  2394.  
  2395.             if(Extra = (struct ViewPortExtra *)GfxLookUp(VPort))
  2396.             {
  2397.                 ScreenWidth    = Extra -> DisplayClip . MaxX - Extra -> DisplayClip . MinX + 1;
  2398.                 ScreenHeight    = Extra -> DisplayClip . MaxY - Extra -> DisplayClip . MinY + 1;
  2399.             }
  2400.             else
  2401.             {
  2402.                 ScreenWidth    = LocalScreen -> Width;
  2403.                 ScreenHeight    = LocalScreen -> Height;
  2404.             }
  2405.         }
  2406.  
  2407.         DepthMask = (1L << GetBitMapDepth(LocalScreen -> RastPort . BitMap)) - 1;
  2408.  
  2409.         switch(Config -> ScreenConfig -> ColourMode)
  2410.         {
  2411.             case COLOUR_SIXTEEN:
  2412.  
  2413.                 if(DepthMask < 15)
  2414.                 {
  2415.                     if(DepthMask >= 7)
  2416.                         Config -> ScreenConfig -> ColourMode = COLOUR_EIGHT;
  2417.                     else
  2418.                     {
  2419.                         if(DepthMask >= 3)
  2420.                             Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2421.                         else
  2422.                             Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2423.                     }
  2424.                 }
  2425.  
  2426.                 break;
  2427.  
  2428.             case COLOUR_EIGHT:
  2429.  
  2430.                 if(DepthMask < 7)
  2431.                 {
  2432.                     if(DepthMask >= 3)
  2433.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2434.                     else
  2435.                         Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2436.                 }
  2437.  
  2438.                 break;
  2439.  
  2440.             case COLOUR_AMIGA:
  2441.  
  2442.                 if(DepthMask < 3)
  2443.                     Config -> ScreenConfig -> ColourMode = COLOUR_MONO;
  2444.  
  2445.                 break;
  2446.         }
  2447.  
  2448.         if(!(DrawInfo = GetScreenDrawInfo(LocalScreen)))
  2449.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  2450.  
  2451.         CreateMenuGlyphs(LocalScreen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  2452.  
  2453.         SZ_SizeSetup(LocalScreen,&UserFont);
  2454.  
  2455.             /* Obtain visual info (whatever that may be). */
  2456.  
  2457.         if(!(VisualInfo = GetVisualInfo(LocalScreen,TAG_DONE)))
  2458.         {
  2459.                 /* Delete the DrawInfo now, or it won't
  2460.                  * get freed during shutdown.
  2461.                  */
  2462.  
  2463.             FreeScreenDrawInfo(LocalScreen,DrawInfo);
  2464.  
  2465.             DrawInfo = NULL;
  2466.  
  2467.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  2468.         }
  2469.  
  2470.         if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && !Config -> ScreenConfig -> SplitStatus)
  2471.             FullWidth = StatusWidth;
  2472.         else
  2473.             FullWidth = 0;
  2474.  
  2475.         if(WindowBox . Left != -1)
  2476.         {
  2477.             SomeTags[Index  ] . ti_Tag    = WA_Left;
  2478.             SomeTags[Index++] . ti_Data    = WindowBox . Left;
  2479.             SomeTags[Index  ] . ti_Tag    = WA_Top;
  2480.             SomeTags[Index++] . ti_Data    = WindowBox . Top;
  2481.  
  2482.             SomeTags[Index  ] . ti_Tag    = WA_Width;
  2483.             SomeTags[Index++] . ti_Data    = WindowBox . Width;
  2484.             SomeTags[Index  ] . ti_Tag    = WA_Height;
  2485.             SomeTags[Index++] . ti_Data    = WindowBox . Height;
  2486.  
  2487.             WindowBox . Left = -1;
  2488.         }
  2489.         else
  2490.         {
  2491.             LONG WindowLeft = -1,WindowTop = -1,DummyWidth,DummyHeight;
  2492.  
  2493.             GetWindowInfo(WINDOW_MAIN,&WindowLeft,&WindowTop,&DummyWidth,&DummyHeight,0,0);
  2494.  
  2495.             if(Config -> TerminalConfig -> NumColumns < 20)
  2496.             {
  2497.                 LONG Width = GetScreenWidth(NULL);
  2498.  
  2499.                 if(FullWidth && Width < FullWidth)
  2500.                 {
  2501.                     SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2502.                     SomeTags[Index++] . ti_Data    = FullWidth;
  2503.                 }
  2504.                 else
  2505.                 {
  2506.                     SomeTags[Index  ] . ti_Tag    = WA_Width;
  2507.                     SomeTags[Index++] . ti_Data    = Width;
  2508.                 }
  2509.             }
  2510.             else
  2511.             {
  2512.                 SomeTags[Index  ] . ti_Tag    = WA_InnerWidth;
  2513.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumColumns * TextFontWidth;
  2514.             }
  2515.  
  2516.             if(Config -> TerminalConfig -> NumLines < 20)
  2517.             {
  2518.                 SomeTags[Index  ] . ti_Tag    = WA_Height;
  2519.                 SomeTags[Index++] . ti_Data    = GetScreenHeight(NULL) - (LocalScreen -> BarHeight + 1);
  2520.             }
  2521.             else
  2522.             {
  2523.                 SomeTags[Index  ] . ti_Tag    = WA_InnerHeight;
  2524.                 SomeTags[Index++] . ti_Data    = Config -> TerminalConfig -> NumLines * TextFontHeight + StatusHeight;
  2525.             }
  2526.  
  2527.             if(WindowLeft != -1)
  2528.             {
  2529.                 SomeTags[Index  ] . ti_Tag    = WA_Left;
  2530.                 SomeTags[Index++] . ti_Data    = WindowLeft;
  2531.             }
  2532.             else
  2533.             {
  2534.                 SomeTags[Index  ] . ti_Tag    = WA_Left;
  2535.                 SomeTags[Index++] . ti_Data    = GetScreenLeft(NULL);
  2536.             }
  2537.  
  2538.             if(WindowTop != -1)
  2539.             {
  2540.                 SomeTags[Index  ] . ti_Tag    = WA_Top;
  2541.                 SomeTags[Index++] . ti_Data    = WindowTop;
  2542.             }
  2543.         }
  2544.  
  2545.         SomeTags[Index] . ti_Tag = TAG_DONE;
  2546.  
  2547.             /* Open the main window. */
  2548.  
  2549.         if(!(Window = OpenWindowTags(NULL,
  2550.             WA_MaxHeight,        LocalScreen -> Height,
  2551.             WA_MaxWidth,        LocalScreen -> Width,
  2552.             WA_SmartRefresh,    TRUE,
  2553.             WA_CustomScreen,    LocalScreen,
  2554.             WA_NewLookMenus,    TRUE,
  2555.             WA_RMBTrap,        TRUE,
  2556.             WA_IDCMP,        DEFAULT_IDCMP,
  2557.             WA_DragBar,        TRUE,
  2558.             WA_DepthGadget,        TRUE,
  2559.             WA_CloseGadget,        TRUE,
  2560.             WA_SizeGadget,        TRUE,
  2561.             WA_SizeBBottom,        Config -> ScreenConfig -> StatusLine == STATUSLINE_DISABLED || Config -> ScreenConfig -> SplitStatus,
  2562.             WA_NoCareRefresh,    TRUE,
  2563.             WA_Title,        ScreenTitle,
  2564.             WA_MenuHelp,        TRUE,
  2565.  
  2566.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  2567.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  2568.  
  2569.             TAG_MORE,        SomeTags,
  2570.         TAG_DONE)))
  2571.         {
  2572.                 /* Delete the DrawInfo now, or it won't
  2573.                  * get freed during shutdown.
  2574.                  */
  2575.  
  2576.             FreeScreenDrawInfo(LocalScreen,DrawInfo);
  2577.  
  2578.             DrawInfo = NULL;
  2579.  
  2580.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2581.         }
  2582.  
  2583.         if(StatusHeight)
  2584.         {
  2585.             StatusDisplayHeight = StatusHeight;
  2586.  
  2587.             CopyMem(Window -> RPort,StatusRPort = &StatusRastPort,sizeof(struct RastPort));
  2588.  
  2589.             StatusRPort -> BitMap = Window -> RPort -> BitMap;
  2590.         }
  2591.         else
  2592.             StatusRPort = NULL;
  2593.  
  2594.             /* Create a user clip region to keep text from
  2595.              * leaking into the window borders.
  2596.              */
  2597.  
  2598.         if(!(ClipRegion = NewRegion()))
  2599.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  2600.         else
  2601.         {
  2602.             struct Rectangle RegionRectangle;
  2603.  
  2604.                 /* Adjust the region to match the inner window area. */
  2605.  
  2606.             RegionRectangle . MinX = Window -> BorderLeft;
  2607.             RegionRectangle . MinY = Window -> BorderTop;
  2608.             RegionRectangle . MaxX = Window -> Width - (Window -> BorderRight + 1);
  2609.             RegionRectangle . MaxY = Window -> Height - (Window -> BorderBottom + 1);
  2610.  
  2611.                 /* Establish the region. */
  2612.  
  2613.             OrRectRegion(ClipRegion,&RegionRectangle);
  2614.  
  2615.                 /* Install the region. */
  2616.  
  2617.             OldRegion = InstallClipRegion(Window -> WLayer,ClipRegion);
  2618.         }
  2619.  
  2620.         if(FullWidth < 40 * TextFontWidth)
  2621.             FullWidth = 40 * TextFontWidth;
  2622.  
  2623.         Width    = Window -> BorderLeft + FullWidth + Window -> BorderRight;
  2624.         Height    = Window -> BorderTop + 20 * TextFontHeight + Window -> BorderBottom + StatusHeight;
  2625.  
  2626.         if(ChatMode && !(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0]))
  2627.             Height += UserFontHeight + 2;
  2628.  
  2629.         WindowLimits(Window,Width,Height,0,0);
  2630.  
  2631.         if(WorkbenchBase)
  2632.         {
  2633.             if(WorkbenchPort = CreateMsgPort())
  2634.             {
  2635.                 if(!(WorkbenchWindow = AddAppWindow(0,0,Window,WorkbenchPort,TAG_DONE)))
  2636.                 {
  2637.                     DeleteMsgPort(WorkbenchPort);
  2638.  
  2639.                     WorkbenchPort = NULL;
  2640.                 }
  2641.             }
  2642.         }
  2643.     }
  2644.     else
  2645.     {
  2646.         struct DimensionInfo    DimensionInfo;
  2647.         WORD            MaxDepth,
  2648.                     ScreenDepth;
  2649.  
  2650.         if(ModeNotAvailable(Config -> ScreenConfig -> DisplayMode))
  2651.         {
  2652.             struct Screen *PubScreen;
  2653.  
  2654.             if(PubScreen = LockPubScreen(NULL))
  2655.             {
  2656.                 Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  2657.  
  2658.                 if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2659.                 {
  2660.                     LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  2661.                         Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  2662.  
  2663.                     if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  2664.                         Config -> ScreenConfig -> DisplayWidth = Width;
  2665.  
  2666.                     if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  2667.                         Config -> ScreenConfig -> DisplayHeight = Height;
  2668.                 }
  2669.  
  2670.                 UnlockPubScreen(NULL,PubScreen);
  2671.             }
  2672.         }
  2673.  
  2674.         if(!QueryOverscan(Config -> ScreenConfig -> DisplayMode,&DisplayClip,Config -> ScreenConfig -> OverscanType))
  2675.         {
  2676.             OpenFailed = TRUE;
  2677.  
  2678.             ErrorCode = ModeNotAvailable(Config -> ScreenConfig -> DisplayMode);
  2679.  
  2680.             goto OpenS;
  2681.         }
  2682.  
  2683.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  2684.         {
  2685.             UWORD    MaxWidth,
  2686.                 MaxHeight,
  2687.                 Width,
  2688.                 Height;
  2689.  
  2690.             MaxWidth    = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2691.             MaxHeight    = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2692.  
  2693.             if(Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayHeight && AslBase -> lib_Version >= 38)
  2694.             {
  2695.                 ScreenWidth    = Config -> ScreenConfig -> DisplayWidth;
  2696.                 ScreenHeight    = Config -> ScreenConfig -> DisplayHeight;
  2697.             }
  2698.             else
  2699.             {
  2700.                 ScreenWidth    = MaxWidth;
  2701.                 ScreenHeight    = MaxHeight;
  2702.             }
  2703.  
  2704.             if(Config -> TerminalConfig -> NumColumns < 20)
  2705.                 Width = MaxWidth = ScreenWidth;
  2706.             else
  2707.             {
  2708.                 Width = TextFontWidth * Config -> TerminalConfig -> NumColumns;
  2709.  
  2710.                 ScreenWidth = 0;
  2711.             }
  2712.  
  2713.             if(Config -> TerminalConfig -> NumLines < 20)
  2714.                 Height = MaxHeight = ScreenHeight;
  2715.             else
  2716.             {
  2717.                 Height = TextFontHeight * Config -> TerminalConfig -> NumLines;
  2718.  
  2719.                 if(Config -> ScreenConfig -> TitleBar)
  2720.                     Height += UserFontHeight + 3;
  2721.  
  2722.                 if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED)
  2723.                 {
  2724.                     if(Config -> ScreenConfig -> StatusLine == STATUSLINE_COMPRESSED)
  2725.                         Height += UserFontHeight;
  2726.                     else
  2727.                         Height += 4 + (2 + 2 * UserFontHeight + 2);
  2728.                 }
  2729.  
  2730.                 ScreenHeight = 0;
  2731.             }
  2732.  
  2733.             if(Height > MaxHeight)
  2734.                 Height = MaxHeight;
  2735.  
  2736.             if(Width > MaxWidth)
  2737.                 Width = MaxWidth;
  2738.  
  2739.             if(DimensionInfo . MinRasterWidth <= Width && Width <= DimensionInfo . MaxRasterWidth && Width < MaxWidth)
  2740.             {
  2741.                 UWORD Half;
  2742.  
  2743.                 Width = MaxWidth - Width;
  2744.  
  2745.                 Half = Width / 2;
  2746.  
  2747.                 DisplayClip . MinX += Half;
  2748.                 DisplayClip . MaxX -= Width - Half;
  2749.             }
  2750.  
  2751.             if(DimensionInfo . MinRasterHeight <= Height && Height <= DimensionInfo . MaxRasterHeight)
  2752.                 DisplayClip . MaxY = DisplayClip . MinY + Height - 1;
  2753.  
  2754.             if(!ScreenWidth)
  2755.                 ScreenWidth = DisplayClip . MaxX - DisplayClip . MinX + 1;
  2756.  
  2757.             if(!ScreenHeight)
  2758.                 ScreenHeight = DisplayClip . MaxY - DisplayClip . MinY + 1;
  2759.  
  2760.             MaxDepth = DimensionInfo . MaxDepth;
  2761.         }
  2762.         else
  2763.         {
  2764.             ScreenWidth = ScreenHeight = 0;
  2765.             MaxDepth = 4;
  2766.         }
  2767.  
  2768.             /* We'll configure the screen parameters at
  2769.              * run time, at first we'll set up the screen
  2770.              * depth.
  2771.              */
  2772.  
  2773. PenReset:    if(!Config -> ScreenConfig -> UsePens && Kick30)
  2774.         {
  2775.             for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2776.                 PenArray[i] = Config -> ScreenConfig -> PenArray[i];
  2777.  
  2778.             PenArray[i] = (UWORD)~0;
  2779.         }
  2780.         else
  2781.         {
  2782.             UWORD *Data;
  2783.  
  2784.             switch(Config -> ScreenConfig -> ColourMode)
  2785.             {
  2786.                 case COLOUR_EIGHT:
  2787.  
  2788.                     Data = ANSIPens;
  2789.                     break;
  2790.  
  2791.                 case COLOUR_SIXTEEN:
  2792.  
  2793.                     if(IntuitionBase -> LibNode . lib_Version >= 39)
  2794.                         Data = NewEGAPens;
  2795.                     else
  2796.                         Data = EGAPens;
  2797.  
  2798.                     break;
  2799.  
  2800.                 case COLOUR_AMIGA:
  2801.  
  2802.                     Data = StandardPens;
  2803.                     break;
  2804.  
  2805.                 default:
  2806.  
  2807.                     Data = NULL;
  2808.                     break;
  2809.             }
  2810.  
  2811.             if(Data)
  2812.             {
  2813.                 for(i = DETAILPEN ; i <= BARTRIMPEN ; i++)
  2814.                     PenArray[i] = Data[i];
  2815.  
  2816.                 PenArray[i] = (UWORD)~0;
  2817.             }
  2818.         }
  2819.  
  2820.         switch(Config -> ScreenConfig -> ColourMode)
  2821.         {
  2822.             case COLOUR_EIGHT:
  2823.  
  2824.                     // Special screen depth requested?
  2825.  
  2826.                 if(Config -> ScreenConfig -> Depth)
  2827.                 {
  2828.                         // The minimum number of colours required
  2829.  
  2830.                     if(Config -> ScreenConfig -> Blinking)
  2831.                         ScreenDepth = 4;
  2832.                     else
  2833.                         ScreenDepth = 3;
  2834.  
  2835.                         // This is what the user wanted
  2836.  
  2837.                     RealDepth = Config -> ScreenConfig -> Depth;
  2838.  
  2839.                         // Too deep for this display mode?
  2840.  
  2841.                     if(RealDepth > MaxDepth)
  2842.                         RealDepth = MaxDepth;
  2843.  
  2844.                         // Less colours than required?
  2845.  
  2846.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2847.                         RealDepth = ScreenDepth;
  2848.  
  2849.                         // Not enough colours to display it?
  2850.  
  2851.                     if(RealDepth < ScreenDepth)
  2852.                     {
  2853.                             // Return to standard mode
  2854.  
  2855.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2856.  
  2857.                         ConfigChanged = TRUE;
  2858.  
  2859.                         goto PenReset;
  2860.                     }
  2861.                 }
  2862.                 else
  2863.                 {
  2864.                         // The minimum number of colours
  2865.  
  2866.                     if(Config -> ScreenConfig -> Blinking)
  2867.                         ScreenDepth = 4;
  2868.                     else
  2869.                         ScreenDepth = 3;
  2870.  
  2871.                         // Too many for this mode?
  2872.  
  2873.                     if(ScreenDepth > MaxDepth)
  2874.                     {
  2875.                             // Return to standard mode
  2876.  
  2877.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2878.  
  2879.                         ConfigChanged = TRUE;
  2880.  
  2881.                         goto PenReset;
  2882.                     }
  2883.  
  2884.                     RealDepth = ScreenDepth;
  2885.                 }
  2886.  
  2887.                 TagArray[Count++] = SA_Pens;
  2888.                 TagArray[Count++] = (LONG)PenArray;
  2889.  
  2890.                 TagArray[Count++] = SA_BlockPen;
  2891.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2892.  
  2893.                 TagArray[Count++] = SA_DetailPen;
  2894.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2895.  
  2896.                 break;
  2897.  
  2898.             case COLOUR_SIXTEEN:
  2899.  
  2900.                 if(Config -> ScreenConfig -> Depth)
  2901.                 {
  2902.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2903.                         ScreenDepth = 5;
  2904.                     else
  2905.                         ScreenDepth = 4;
  2906.  
  2907.                     RealDepth = Config -> ScreenConfig -> Depth;
  2908.  
  2909.                     if(RealDepth > MaxDepth)
  2910.                         RealDepth = MaxDepth;
  2911.  
  2912.                     if(RealDepth < ScreenDepth && ScreenDepth <= MaxDepth)
  2913.                         RealDepth = ScreenDepth;
  2914.  
  2915.                     if(RealDepth < ScreenDepth)
  2916.                     {
  2917.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2918.  
  2919.                         ConfigChanged = TRUE;
  2920.  
  2921.                         goto PenReset;
  2922.                     }
  2923.                 }
  2924.                 else
  2925.                 {
  2926.                     if(Config -> ScreenConfig -> Blinking && MaxDepth > 4)
  2927.                         ScreenDepth = 5;
  2928.                     else
  2929.                         ScreenDepth = 4;
  2930.  
  2931.                     if(ScreenDepth > MaxDepth)
  2932.                     {
  2933.                         Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  2934.  
  2935.                         ConfigChanged = TRUE;
  2936.  
  2937.                         goto PenReset;
  2938.                     }
  2939.  
  2940.                     RealDepth = ScreenDepth;
  2941.                 }
  2942.  
  2943.                 TagArray[Count++] = SA_Pens;
  2944.                 TagArray[Count++] = (LONG)PenArray;
  2945.  
  2946.                 TagArray[Count++] = SA_BlockPen;
  2947.                 TagArray[Count++] = PenArray[SHADOWPEN];
  2948.  
  2949.                 TagArray[Count++] = SA_DetailPen;
  2950.                 TagArray[Count++] = PenArray[BACKGROUNDPEN];
  2951.  
  2952.                 break;
  2953.  
  2954.             case COLOUR_MONO:
  2955.  
  2956.                 if(Config -> ScreenConfig -> Depth)
  2957.                     RealDepth = Config -> ScreenConfig -> Depth;
  2958.                 else
  2959.                     RealDepth = 1;
  2960.  
  2961.                 if(RealDepth > MaxDepth)
  2962.                     RealDepth = MaxDepth;
  2963.  
  2964.                 break;
  2965.  
  2966.             case COLOUR_AMIGA:
  2967.  
  2968.                 if(Config -> ScreenConfig -> Depth)
  2969.                     RealDepth = Config -> ScreenConfig -> Depth;
  2970.                 else
  2971.                     RealDepth = 2;
  2972.  
  2973.                 if(RealDepth > MaxDepth)
  2974.                     RealDepth = MaxDepth;
  2975.  
  2976.                 TagArray[Count++] = SA_Pens;
  2977.                 TagArray[Count++] = (LONG)PenArray;
  2978.  
  2979.                 break;
  2980.         }
  2981.  
  2982.             /* Add the depth value. */
  2983.  
  2984.         TagArray[Count++] = SA_Depth;
  2985.         TagArray[Count++] = RealDepth;
  2986.  
  2987.             /* Terminate the tag array. */
  2988.  
  2989.         TagArray[Count] = TAG_END;
  2990.  
  2991.             /* Set the plane mask. */
  2992.  
  2993.         DepthMask = (1L << RealDepth) - 1;
  2994.  
  2995. #if defined(_M68030)
  2996. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'030 ",TermDate,TermIDString);
  2997. #endif
  2998.  
  2999. #if defined(_M68040)
  3000. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"'040 ",TermDate,TermIDString);
  3001. #endif
  3002.  
  3003. #if !defined(_M68030) && !defined(_M68040)
  3004. OpenS:        SPrintf(ScreenTitle,LocaleString(MSG_TERMINIT_SCREENTITLE_TXT),TermName,"",TermDate,TermIDString);
  3005. #endif
  3006.  
  3007.         /* ALWAYS */
  3008.         {
  3009.             BYTE Interleaved;
  3010.  
  3011.             if(Config -> ScreenConfig -> FasterLayout && Kick30 && RealDepth > 1)
  3012.                 Interleaved = TRUE;
  3013.             else
  3014.                 Interleaved = FALSE;
  3015.  
  3016.             StatusSizeSetup(NULL,&StatusWidth,&StatusHeight);
  3017.  
  3018.             if(StatusHeight && StatusWidth > ScreenWidth)
  3019.                 ScreenWidth = StatusWidth;
  3020.  
  3021.             if(Screen = (struct Screen *)OpenScreenTags(NULL,
  3022.                 ScreenWidth  ? SA_Width  : TAG_IGNORE,    ScreenWidth,
  3023.                 ScreenHeight ? SA_Height : TAG_IGNORE,    ScreenHeight,
  3024.  
  3025.                 SA_Title,    ScreenTitle,
  3026.                 SA_Left,    DisplayClip . MinX,
  3027.                 SA_DClip,    &DisplayClip,
  3028.                 SA_DisplayID,    Config -> ScreenConfig -> DisplayMode,
  3029.                 SA_Font,    &UserFont,
  3030.                 SA_Behind,    TRUE,
  3031.                 SA_AutoScroll,    TRUE,
  3032.                 SA_ShowTitle,    Config -> ScreenConfig -> TitleBar,
  3033.                 SA_PubName,    TermIDString,
  3034.                 SA_ErrorCode,    &ErrorCode,
  3035.                 SA_Interleaved,    Interleaved,
  3036.                 SA_BackFill,    &BackfillHook,
  3037.                 TAG_MORE,    TagArray,
  3038.             TAG_END))
  3039.             {
  3040.                 if(RealDepth > 1 && !Config -> ScreenConfig -> FasterLayout)
  3041.                 {
  3042.                     UseMasking = TRUE;
  3043.  
  3044.                     if(Kick30)
  3045.                     {
  3046.                         if(GetBitMapAttr(Screen -> RastPort . BitMap,BMA_FLAGS) & BMF_INTERLEAVED)
  3047.                             UseMasking = FALSE;
  3048.                     }
  3049.                 }
  3050.                 else
  3051.                     UseMasking = FALSE;
  3052.             }
  3053.         }
  3054.  
  3055.             /* We've got an error. */
  3056.  
  3057.         if(!Screen)
  3058.         {
  3059.             if(!OpenFailed)
  3060.             {
  3061.                 struct Screen *PubScreen;
  3062.  
  3063.                 switch(ErrorCode)
  3064.                 {
  3065.                         /* Can't open screen with these display
  3066.                          * modes.
  3067.                          */
  3068.  
  3069.                     case OSERR_NOMONITOR:
  3070.                     case OSERR_NOCHIPS:
  3071.                     case OSERR_UNKNOWNMODE:
  3072.                     case OSERR_NOTAVAILABLE:
  3073.  
  3074.                         if(PubScreen = LockPubScreen(NULL))
  3075.                         {
  3076.                             struct DimensionInfo DimensionInfo;
  3077.  
  3078.                             Config -> ScreenConfig -> DisplayMode = GetVPModeID(&PubScreen -> ViewPort);
  3079.  
  3080.                             if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,Config -> ScreenConfig -> DisplayMode))
  3081.                             {
  3082.                                 LONG    Width    = DimensionInfo . TxtOScan . MaxX - DimensionInfo . TxtOScan . MinX + 1,
  3083.                                     Height    = DimensionInfo . TxtOScan . MaxY - DimensionInfo . TxtOScan . MinY + 1;
  3084.  
  3085.                                 if(Width != Config -> ScreenConfig -> DisplayWidth && Config -> ScreenConfig -> DisplayWidth)
  3086.                                     Config -> ScreenConfig -> DisplayWidth = Width;
  3087.  
  3088.                                 if(Height != Config -> ScreenConfig -> DisplayHeight && Config -> ScreenConfig -> DisplayHeight)
  3089.                                     Config -> ScreenConfig -> DisplayHeight = Height;
  3090.                             }
  3091.  
  3092.                             UnlockPubScreen(NULL,PubScreen);
  3093.                         }
  3094.                         else
  3095.                             Config -> ScreenConfig -> DisplayMode = DEFAULT_MONITOR_ID | HIRESLACE_KEY;
  3096.  
  3097.                         OpenFailed = TRUE;
  3098.  
  3099.                         goto OpenS;
  3100.  
  3101.                     case OSERR_PUBNOTUNIQUE:
  3102.  
  3103.                         return(LocaleString(MSG_TERMINIT_SCREEN_ID_ALREADY_IN_USE_TXT));
  3104.                 }
  3105.             }
  3106.  
  3107.                 /* Some different error, probably out of
  3108.                  * memory.
  3109.                  */
  3110.  
  3111.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_SCREEN_TXT));
  3112.         }
  3113.  
  3114.         if(!(DrawInfo = GetScreenDrawInfo(Screen)))
  3115.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_SCREEN_DRAWINFO_TXT));
  3116.  
  3117.         CreateMenuGlyphs(Screen,DrawInfo,&AmigaGlyph,&CheckGlyph);
  3118.  
  3119.         VPort = &Screen -> ViewPort;
  3120.  
  3121.         ScreenWidth    = Screen -> Width;
  3122.         ScreenHeight    = Screen -> Height;
  3123.  
  3124.         StatusSizeSetup(Screen,&StatusWidth,&StatusHeight);
  3125.  
  3126.             /* Obtain visual info (whatever that may be). */
  3127.  
  3128.         if(!(VisualInfo = GetVisualInfo(Screen,TAG_DONE)))
  3129.         {
  3130.                 /* Delete the DrawInfo now, or it won't
  3131.                  * get freed during shutdown.
  3132.                  */
  3133.  
  3134.             FreeScreenDrawInfo(Screen,DrawInfo);
  3135.  
  3136.             DrawInfo = NULL;
  3137.  
  3138.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OBTAIN_VISUAL_INFO_TXT));
  3139.         }
  3140.  
  3141.         if(Config -> ScreenConfig -> TitleBar)
  3142.         {
  3143.             Top = Screen -> BarHeight + 1;
  3144.  
  3145.             Height = Screen -> Height - (Screen -> BarHeight + 1);
  3146.         }
  3147.         else
  3148.         {
  3149.             Top = 0;
  3150.  
  3151.             Height = Screen -> Height;
  3152.         }
  3153.  
  3154.             /* Open the main window. */
  3155.  
  3156.         if(!(Window = OpenWindowTags(NULL,
  3157.             WA_Top,            Top,
  3158.             WA_Left,        0,
  3159.             WA_Width,        Screen -> Width,
  3160.             WA_Height,        Height,
  3161.             WA_Backdrop,        TRUE,
  3162.             WA_Borderless,        TRUE,
  3163.             WA_CustomScreen,    Screen,
  3164.             WA_NewLookMenus,    TRUE,
  3165.             WA_RMBTrap,        TRUE,
  3166.             WA_IDCMP,        DEFAULT_IDCMP | IDCMP_SIZEVERIFY,
  3167.             WA_MenuHelp,        TRUE,
  3168.             WA_NoCareRefresh,    TRUE,
  3169.  
  3170.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3171.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3172.         TAG_DONE)))
  3173.         {
  3174.                 /* Delete the DrawInfo now, or it won't
  3175.                  * get freed during shutdown.
  3176.                  */
  3177.  
  3178.             FreeScreenDrawInfo(Screen,DrawInfo);
  3179.  
  3180.             DrawInfo = NULL;
  3181.  
  3182.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_WINDOW_TXT));
  3183.         }
  3184.  
  3185.         if(StatusHeight)
  3186.         {
  3187.             StatusDisplayHeight = StatusHeight;
  3188.  
  3189.             CopyMem(Window -> RPort,StatusRPort = &StatusRastPort,sizeof(struct RastPort));
  3190.  
  3191.             StatusRPort -> BitMap = Window -> RPort -> BitMap;
  3192.         }
  3193.         else
  3194.             StatusRPort = NULL;
  3195.     }
  3196.  
  3197.         // Now check if a nonzero background colour should be used.
  3198.         // If this is the case, set up a special BitMap that will be
  3199.         // used in place of a RectFill() operation.
  3200.  
  3201.     if(DrawInfo->dri_Pens[BACKGROUNDPEN])
  3202.     {
  3203.         UWORD Pen = DrawInfo->dri_Pens[BACKGROUNDPEN],i;
  3204.  
  3205.         InitBitMap(&BackfillBitMap,DrawInfo->dri_Depth,Window->WScreen->Width,Window->WScreen->Height);
  3206.  
  3207.         for(i = 0 ; i < BackfillBitMap.Depth ; i++)
  3208.         {
  3209.             if(Pen & (1L << i))
  3210.                 BackfillBitMap.Planes[i] = (PLANEPTR)0xFFFFFFFF;
  3211.             else
  3212.                 BackfillBitMap.Planes[i] = (PLANEPTR)NULL;
  3213.         }
  3214.  
  3215.         BackfillTag = WA_BackFill;
  3216.     }
  3217.     else
  3218.         BackfillTag = TAG_IGNORE;
  3219.  
  3220.         /* Fill the `default' colour with current values. */
  3221.  
  3222.     if(!Config -> ScreenConfig -> UseWorkbench && Initializing && !SharedScreen)
  3223.     {
  3224.         if(Kick30)
  3225.         {
  3226.             ULONG RGB[3 * 16];
  3227.  
  3228.             GetRGB32(VPort -> ColorMap,0,16,RGB);
  3229.  
  3230.             ANSIColourTable        = CreateColourTable(8,ANSIColours,NULL);
  3231.             EGAColourTable        = CreateColourTable(16,EGAColours,NULL);
  3232.             DefaultColourTable    = CreateColourTable(16,NULL,RGB);
  3233.             MonoColourTable        = CreateColourTable(2,AtomicColours,NULL);
  3234.         }
  3235.  
  3236.         for(i = 0 ; i < 16 ; i++)
  3237.             DefaultColours[i] = GetRGB4(VPort -> ColorMap,i);
  3238.  
  3239.         Initializing = FALSE;
  3240.     }
  3241.  
  3242.         /* Load the approriate colours. */
  3243.  
  3244.     if(LoadColours)
  3245.     {
  3246.         Default2CurrentPalette(Config);
  3247.  
  3248.         LoadColours = FALSE;
  3249.     }
  3250.  
  3251.         /* Reset the current colours and the blinking equivalents. */
  3252.  
  3253.     PaletteSetup(Config);
  3254.  
  3255.     if(!Config -> ScreenConfig -> UseWorkbench && !SharedScreen)
  3256.         LoadColourTable(VPort,NormalColourTable,NormalColours,PaletteSize);
  3257.  
  3258.         /* Get the vanilla rendering pens. */
  3259.  
  3260.     RenderPens[0] = DrawInfo -> dri_Pens[BACKGROUNDPEN];
  3261.     RenderPens[1] = DrawInfo -> dri_Pens[TEXTPEN];
  3262.     RenderPens[2] = DrawInfo -> dri_Pens[SHINEPEN];
  3263.     RenderPens[3] = DrawInfo -> dri_Pens[FILLPEN];
  3264.  
  3265.         /* Are we to use the Workbench screen for text output? */
  3266.  
  3267.     if(Config -> ScreenConfig -> UseWorkbench || (SharedScreen && Kick30))
  3268.     {
  3269.         if(Kick30 && (Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT || Config -> ScreenConfig -> ColourMode == COLOUR_SIXTEEN))
  3270.         {
  3271.             ULONG    R,G,B;
  3272.             BYTE    GotAll = TRUE;
  3273.             WORD    NumPens;
  3274.  
  3275.             if(Config -> ScreenConfig -> ColourMode == COLOUR_EIGHT)
  3276.                 NumPens = 8;
  3277.             else
  3278.                 NumPens = 16;
  3279.  
  3280.             for(i = 0 ; i < 32 ; i++)
  3281.                 MappedPens[1][i] = FALSE;
  3282.  
  3283.                 /* Allocate the text rendering pens, note that
  3284.                  * we will use the currently installed palette
  3285.                  * to obtain those pens which match them best.
  3286.                  * The user will be unable to change these
  3287.                  * colours.
  3288.                  */
  3289.  
  3290.             if(NormalColourTable)
  3291.             {
  3292.                 for(i = 0 ; i < NumPens ; i++)
  3293.                 {
  3294.                         /* Try to obtain a matching pen. */
  3295.  
  3296.                     if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,NormalColourTable -> Entry[i] . Red,NormalColourTable -> Entry[i] . Green,NormalColourTable -> Entry[i] . Blue,
  3297.                         OBP_FailIfBad,TRUE,
  3298.                     TAG_DONE)) == -1)
  3299.                     {
  3300.                         MappedPens[1][i] = FALSE;
  3301.  
  3302.                         GotAll = FALSE;
  3303.  
  3304.                         break;
  3305.                     }
  3306.                     else
  3307.                         MappedPens[1][i] = TRUE;
  3308.                 }
  3309.             }
  3310.             else
  3311.             {
  3312.                 for(i = 0 ; i < NumPens ; i++)
  3313.                 {
  3314.                         /* Split the 12 bit colour palette entry. */
  3315.  
  3316.                     R = (NormalColours[i] >> 8) & 0xF;
  3317.                     G = (NormalColours[i] >> 4) & 0xF;
  3318.                     B =  NormalColours[i]       & 0xF;
  3319.  
  3320.                         /* Try to obtain a matching pen. */
  3321.  
  3322.                     if((MappedPens[0][i] = ObtainBestPen(VPort -> ColorMap,SPREAD((R << 4) | R),SPREAD((G << 4) | G),SPREAD((B << 4) | B),
  3323.                         OBP_FailIfBad,TRUE,
  3324.                     TAG_DONE)) == -1)
  3325.                     {
  3326.                         MappedPens[1][i] = FALSE;
  3327.  
  3328.                         GotAll = FALSE;
  3329.  
  3330.                         break;
  3331.                     }
  3332.                     else
  3333.                         MappedPens[1][i] = TRUE;
  3334.                 }
  3335.             }
  3336.  
  3337.                 /* Did we get what we wanted? */
  3338.  
  3339.             if(!GotAll)
  3340.             {
  3341.                     /* Release all the pens we succeeded
  3342.                      * in allocating.
  3343.                      */
  3344.  
  3345.                 for(i = 0 ; i < NumPens ; i++)
  3346.                 {
  3347.                     if(MappedPens[1][i])
  3348.                         ReleasePen(VPort -> ColorMap,MappedPens[0][i]);
  3349.                 }
  3350.  
  3351.                     /* Use the default rendering pens. */
  3352.  
  3353.                 for(i = 0 ; i < 4 ; i++)
  3354.                 {
  3355.                     MappedPens[0][i] = RenderPens[i];
  3356.                     MappedPens[1][i] = FALSE;
  3357.                 }
  3358.  
  3359.                     /* Set the remaining pens to defaults. */
  3360.  
  3361.                 for(i = 4 ; i < NumPens ; i++)
  3362.                 {
  3363.                     MappedPens[0][i] = RenderPens[1];
  3364.                     MappedPens[1][i] = FALSE;
  3365.                 }
  3366.  
  3367.                     /* Can't do anything else. */
  3368.  
  3369.                 Config -> ScreenConfig -> ColourMode = COLOUR_AMIGA;
  3370.             }
  3371.             else
  3372.                 AllocatedPens = TRUE;
  3373.         }
  3374.         else
  3375.         {
  3376.                 /* Use the default rendering pens. */
  3377.  
  3378.             if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  3379.             {
  3380.                 for(i = 0 ; i < 4 ; i++)
  3381.                 {
  3382.                     MappedPens[0][i] = RenderPens[i];
  3383.                     MappedPens[1][i] = FALSE;
  3384.                 }
  3385.  
  3386.                     /* Set the remaining pens to defaults. */
  3387.  
  3388.                 for(i = 4 ; i < 16 ; i++)
  3389.                 {
  3390.                     MappedPens[0][i] = RenderPens[1];
  3391.                     MappedPens[1][i] = FALSE;
  3392.                 }
  3393.             }
  3394.             else
  3395.             {
  3396.                 for(i = 0 ; i < 16 ; i++)
  3397.                 {
  3398.                     MappedPens[0][i] = RenderPens[i & 1];
  3399.                     MappedPens[1][i] = FALSE;
  3400.                 }
  3401.             }
  3402.         }
  3403.  
  3404.         for(i = 0 ; i < 16 ; i++)
  3405.         {
  3406.             MappedPens[0][i + 16] = MappedPens[0][i];
  3407.             MappedPens[1][i + 16] = FALSE;
  3408.         }
  3409.     }
  3410.     else
  3411.     {
  3412.             /* Reset the colour translation table. */
  3413.  
  3414.         for(i = 0 ; i < 32 ; i++)
  3415.         {
  3416.             MappedPens[0][i] = i;
  3417.             MappedPens[1][i] = FALSE;
  3418.         }
  3419.     }
  3420.  
  3421.         /* Determine default text rendering colour. */
  3422.  
  3423.     switch(Config -> ScreenConfig -> ColourMode)
  3424.     {
  3425.         case COLOUR_SIXTEEN:
  3426.  
  3427. //            SafeTextPen = MappedPens[0][15];
  3428.             SafeTextPen = MappedPens[0][7];
  3429.             break;
  3430.  
  3431.         case COLOUR_EIGHT:
  3432.  
  3433.             SafeTextPen = MappedPens[0][7];
  3434.             break;
  3435.  
  3436.         case COLOUR_AMIGA:
  3437.         case COLOUR_MONO:
  3438.  
  3439.             SafeTextPen = MappedPens[0][1];
  3440.             break;
  3441.     }
  3442.  
  3443.         /* Take care of pen and attribute mapping. */
  3444.  
  3445.     if(Config -> EmulationConfig -> UseStandardPens)
  3446.     {
  3447.         for(i = 0 ; i < 16 ; i++)
  3448.         {
  3449.             PenTable[i]        = i;
  3450.             TextAttributeTable[i]    = i;
  3451.         }
  3452.     }
  3453.     else
  3454.     {
  3455.         UBYTE Value;
  3456.  
  3457.         memcpy(PenTable,Config -> EmulationConfig -> Pens,sizeof(Config -> EmulationConfig -> Pens));
  3458.  
  3459.         for(i = 0 ; i < 16 ; i++)
  3460.         {
  3461.             Value = 0;
  3462.  
  3463.             if(i & ATTR_UNDERLINE)
  3464.             {
  3465.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_UNDERLINE])
  3466.                 {
  3467.                     case TEXTATTR_UNDERLINE:
  3468.  
  3469.                         Value |= ATTR_UNDERLINE;
  3470.                         break;
  3471.  
  3472.                     case TEXTATTR_HIGHLIGHT:
  3473.  
  3474.                         Value |= ATTR_HIGHLIGHT;
  3475.                         break;
  3476.  
  3477.                     case TEXTATTR_BLINK:
  3478.  
  3479.                         Value |= ATTR_BLINK;
  3480.                         break;
  3481.  
  3482.                     case TEXTATTR_INVERSE:
  3483.  
  3484.                         Value |= ATTR_INVERSE;
  3485.                         break;
  3486.                 }
  3487.             }
  3488.  
  3489.             if(i & ATTR_HIGHLIGHT)
  3490.             {
  3491.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_HIGHLIGHT])
  3492.                 {
  3493.                     case TEXTATTR_UNDERLINE:
  3494.  
  3495.                         Value |= ATTR_UNDERLINE;
  3496.                         break;
  3497.  
  3498.                     case TEXTATTR_HIGHLIGHT:
  3499.  
  3500.                         Value |= ATTR_HIGHLIGHT;
  3501.                         break;
  3502.  
  3503.                     case TEXTATTR_BLINK:
  3504.  
  3505.                         Value |= ATTR_BLINK;
  3506.                         break;
  3507.  
  3508.                     case TEXTATTR_INVERSE:
  3509.  
  3510.                         Value |= ATTR_INVERSE;
  3511.                         break;
  3512.                 }
  3513.             }
  3514.  
  3515.             if(i & ATTR_BLINK)
  3516.             {
  3517.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_BLINK])
  3518.                 {
  3519.                     case TEXTATTR_UNDERLINE:
  3520.  
  3521.                         Value |= ATTR_UNDERLINE;
  3522.                         break;
  3523.  
  3524.                     case TEXTATTR_HIGHLIGHT:
  3525.  
  3526.                         Value |= ATTR_HIGHLIGHT;
  3527.                         break;
  3528.  
  3529.                     case TEXTATTR_BLINK:
  3530.  
  3531.                         Value |= ATTR_BLINK;
  3532.                         break;
  3533.  
  3534.                     case TEXTATTR_INVERSE:
  3535.  
  3536.                         Value |= ATTR_INVERSE;
  3537.                         break;
  3538.                 }
  3539.             }
  3540.  
  3541.             if(i & ATTR_INVERSE)
  3542.             {
  3543.                 switch(Config -> EmulationConfig -> Attributes[TEXTATTR_INVERSE])
  3544.                 {
  3545.                     case TEXTATTR_UNDERLINE:
  3546.  
  3547.                         Value |= ATTR_UNDERLINE;
  3548.                         break;
  3549.  
  3550.                     case TEXTATTR_HIGHLIGHT:
  3551.  
  3552.                         Value |= ATTR_HIGHLIGHT;
  3553.                         break;
  3554.  
  3555.                     case TEXTATTR_BLINK:
  3556.  
  3557.                         Value |= ATTR_BLINK;
  3558.                         break;
  3559.  
  3560.                     case TEXTATTR_INVERSE:
  3561.  
  3562.                         Value |= ATTR_INVERSE;
  3563.                         break;
  3564.                 }
  3565.             }
  3566.  
  3567.             TextAttributeTable[i] = Value;
  3568.         }
  3569.     }
  3570.  
  3571.         /* Determine window inner dimensions and top/left edge offsets. */
  3572.  
  3573.     UpdateTerminalLimits();
  3574.  
  3575.         /* Set up scaling data (bitmaps & rastports). */
  3576.  
  3577.     if(!CreateScale(Window))
  3578.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_FONT_SCALING_INFO_TXT));
  3579.  
  3580.     if(!CreateOffsetTables())
  3581.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_OFFSET_TABLES_TXT));
  3582.  
  3583.     TabStopMax = Window -> WScreen -> Width / TextFontWidth;
  3584.  
  3585.         /* Allocate the tab stop line. */
  3586.  
  3587.     if(!(TabStops = (BYTE *)AllocVecPooled(TabStopMax,MEMF_ANY | MEMF_CLEAR)))
  3588.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  3589.  
  3590.         /* Push it on the window stack (should become bottommost
  3591.          * entry).
  3592.          */
  3593.  
  3594.     PushWindow(Window);
  3595.  
  3596.     if(TermPort)
  3597.         TermPort -> TopWindow = Window;
  3598.  
  3599.     if(Config -> ScreenConfig -> StatusLine != STATUSLINE_DISABLED && Config -> ScreenConfig -> SplitStatus)
  3600.     {
  3601.         if(!(StatusWindow = OpenWindowTags(NULL,
  3602.             WA_Top,            Window -> TopEdge + Window -> Height,
  3603.             WA_Left,        Window -> LeftEdge,
  3604.             WA_InnerWidth,        StatusWidth,
  3605.             WA_InnerHeight,        StatusHeight,
  3606.             WA_DragBar,        TRUE,
  3607.             WA_DepthGadget,        TRUE,
  3608.             WA_NewLookMenus,    TRUE,
  3609.             WA_Title,        ScreenTitle,
  3610.             WA_CustomScreen,    Window -> WScreen,
  3611.             WA_RMBTrap,        TRUE,
  3612.             WA_CloseGadget,        TRUE,
  3613.             WA_MenuHelp,        TRUE,
  3614.             WA_NoCareRefresh,    TRUE,
  3615.  
  3616.             AmigaGlyph ? WA_AmigaKey  : TAG_IGNORE, AmigaGlyph,
  3617.             CheckGlyph ? WA_Checkmark : TAG_IGNORE, CheckGlyph,
  3618.         TAG_DONE)))
  3619.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  3620.     }
  3621.     else
  3622.         StatusWindow = NULL;
  3623.  
  3624.     if(StatusWindow)
  3625.     {
  3626.         StatusWindow -> UserPort = Window -> UserPort;
  3627.  
  3628.         if(!ModifyIDCMP(StatusWindow,DEFAULT_IDCMP))
  3629.         {
  3630.             StatusWindow -> UserPort = NULL;
  3631.  
  3632.             CloseWindow(StatusWindow);
  3633.             StatusWindow = NULL;
  3634.  
  3635.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_STATUS_WINDOW_TXT));
  3636.         }
  3637.     }
  3638.  
  3639.     UpdateTerminalLimits();
  3640.  
  3641.     RPort = Window -> RPort;
  3642.  
  3643.         /* Default console setup. */
  3644.  
  3645.     CursorX = 0;
  3646.     CursorY    = 0;
  3647.  
  3648.     SetDrMd(RPort,JAM2);
  3649.  
  3650.         /* Set the font. */
  3651.  
  3652.     SetFont(RPort,CurrentFont);
  3653.  
  3654.         /* Redirect AmigaDOS requesters. */
  3655.  
  3656.     OldWindowPtr = ThisProcess -> pr_WindowPtr;
  3657.  
  3658.     ThisProcess -> pr_WindowPtr = (APTR)Window;
  3659.  
  3660.         /* Create the character raster. */
  3661.  
  3662.     if(!CreateRaster())
  3663.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_SCREEN_RASTER_TXT));
  3664.  
  3665.     ConOutputUpdate();
  3666.  
  3667.     ConFontScaleUpdate();
  3668.  
  3669.         /* Set up the scrolling info. */
  3670.  
  3671.     ScrollLineCount = Window -> WScreen -> Height / TextFontHeight;
  3672.  
  3673.     if(!(ScrollLines = (struct ScrollLineInfo *)AllocVecPooled(sizeof(struct ScrollLineInfo) * ScrollLineCount,MEMF_ANY|MEMF_CLEAR)))
  3674.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SCROLLING_SUPPORT_INFO_TXT));
  3675.  
  3676.         /* Create the menu strip. */
  3677.  
  3678.     if(!AttachMenu(NULL))
  3679.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_MENUS_TXT));
  3680.  
  3681.         /* Disable the `Execute ARexx Command' menu item if
  3682.          * the rexx server is not available.
  3683.          */
  3684.  
  3685.     if(!RexxSysBase)
  3686.         OffItem(MEN_EXECUTE_REXX_COMMAND);
  3687.  
  3688.     if(Recording)
  3689.     {
  3690.         OnItem(MEN_RECORD_LINE);
  3691.  
  3692.         CheckItem(MEN_RECORD,TRUE);
  3693.         CheckItem(MEN_RECORD_LINE,RecordingLine);
  3694.     }
  3695.     else
  3696.     {
  3697.         OffItem(MEN_RECORD_LINE);
  3698.  
  3699.         CheckItem(MEN_RECORD,FALSE);
  3700.         CheckItem(MEN_RECORD_LINE,FALSE);
  3701.     }
  3702.  
  3703.     CheckItem(MEN_DISABLE_TRAPS,!(WatchTraps && GenericListTable[GLIST_TRAP] -> ListHeader . mlh_Head -> mln_Succ));
  3704.  
  3705.     if(StatusWindow)
  3706.     {
  3707.         SetMenuStrip(StatusWindow,Menu);
  3708.  
  3709.         StatusWindow -> Flags &= ~WFLG_RMBTRAP;
  3710.  
  3711.         SetDrMd(StatusWindow -> RPort,JAM2);
  3712.     }
  3713.  
  3714.         /* Add a tick if file capture is active. */
  3715.  
  3716.     if(RawCapture)
  3717.     {
  3718.         if(FileCapture)
  3719.             CheckItem(MEN_CAPTURE_TO_RAW_FILE,TRUE);
  3720.         else
  3721.             CheckItem(MEN_CAPTURE_TO_RAW_FILE,FALSE);
  3722.  
  3723.         CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  3724.     }
  3725.     else
  3726.     {
  3727.         if(FileCapture)
  3728.             CheckItem(MEN_CAPTURE_TO_FILE,TRUE);
  3729.         else
  3730.             CheckItem(MEN_CAPTURE_TO_FILE,FALSE);
  3731.     }
  3732.  
  3733.         /* Add a tick if printer capture is active. */
  3734.  
  3735.     CheckItem(MEN_CAPTURE_TO_PRINTER,PrinterCapture != NULL);
  3736.  
  3737.         /* Add a tick if the buffer is frozen. */
  3738.  
  3739.     CheckItem(MEN_FREEZE_BUFFER,BufferFrozen);
  3740.  
  3741.         /* Disable the dialing functions if online. */
  3742.  
  3743.     ObtainSemaphore(&OnlineSemaphore);
  3744.  
  3745.     if(Online)
  3746.         SetDialMenu(FALSE);
  3747.     else
  3748.         SetDialMenu(TRUE);
  3749.  
  3750.     ReleaseSemaphore(&OnlineSemaphore);
  3751.  
  3752.         /* Take care of the chat line. */
  3753.  
  3754.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3755.         OffItem(MEN_CHAT_LINE);
  3756.     else
  3757.         CheckItem(MEN_CHAT_LINE,ChatMode);
  3758.  
  3759.         /* Update the clipboard menus. */
  3760.  
  3761.     SetClipMenu(FALSE);
  3762.  
  3763.     SetTransferMenu(TRUE);
  3764.  
  3765.         /* Disable the `Print Screen' and `Save ASCII' functions
  3766.          * if raster is not enabled.
  3767.          */
  3768.  
  3769.     SetRasterMenu(RasterEnabled);
  3770.  
  3771.         // Take care of the remaining windows
  3772.  
  3773.     if(MatrixWindow)
  3774.         CheckItem(MEN_MATRIX_WINDOW,TRUE);
  3775.  
  3776.     if(InfoWindow)
  3777.         CheckItem(MEN_STATUS_WINDOW,TRUE);
  3778.  
  3779.     if(PacketWindow)
  3780.         CheckItem(MEN_PACKET_WINDOW,TRUE);
  3781.  
  3782.     if(ChatMode)
  3783.         CheckItem(MEN_CHAT_LINE,TRUE);
  3784.  
  3785.     if(FastWindow)
  3786.         CheckItem(MEN_FAST_MACROS_WINDOW,TRUE);
  3787.  
  3788. //    if(TransferProcess)
  3789. //        CheckItem(MEN_UPLOAD_QUEUE_WINDOW,TRUE);
  3790.  
  3791.  
  3792.         /* Enable the menu. */
  3793.  
  3794.     Window -> Flags &= ~WFLG_RMBTRAP;
  3795.  
  3796.     strcpy(EmulationName,LocaleString(MSG_TERMXEM_NO_EMULATION_TXT));
  3797.  
  3798.         /* Create the status server. */
  3799.  
  3800.     Forbid();
  3801.  
  3802.     if(StatusProcess = CreateNewProcTags(
  3803.         NP_Entry,    StatusServer,
  3804.         NP_Name,    "term Status Process",
  3805.         NP_WindowPtr,    -1,
  3806.         NP_Priority,    5,
  3807.     TAG_DONE))
  3808.     {
  3809.         ClrSignal(SIG_HANDSHAKE);
  3810.  
  3811.         Wait(SIG_HANDSHAKE);
  3812.     }
  3813.  
  3814.     Permit();
  3815.  
  3816.         /* Status server has `died'. */
  3817.  
  3818.     if(!StatusProcess)
  3819.         return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_STATUS_TASK_TXT));
  3820.  
  3821.         /* Obtain the default public screen name just in case
  3822.          * we'll need it later.
  3823.          */
  3824.  
  3825.     GetDefaultPubScreen(DefaultPubScreenName);
  3826.  
  3827.         /* Set up the window size. */
  3828.  
  3829.     ScreenSizeStuff();
  3830.  
  3831.         /* Select the default console data processing routine. */
  3832.  
  3833.     Forbid();
  3834.  
  3835.     ConProcessData = ConProcessData8;
  3836.  
  3837.     Permit();
  3838.  
  3839.         /* Handle the remaining terminal setup. */
  3840.  
  3841.     if(Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL && Config -> TerminalConfig -> EmulationFileName[0])
  3842.     {
  3843.         if(!OpenEmulator(Config -> TerminalConfig -> EmulationFileName))
  3844.         {
  3845.             Config -> TerminalConfig -> EmulationMode = EMULATION_ANSIVT100;
  3846.  
  3847.             ResetDisplay = TRUE;
  3848.  
  3849.             RasterEnabled = TRUE;
  3850.  
  3851.             MyEasyRequest(Window,LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_EMULATION_LIBRARY_TXT),Config -> TerminalConfig -> EmulationFileName);
  3852.         }
  3853.         else
  3854.         {
  3855.             if(RasterEnabled)
  3856.                 RasterEnabled = FALSE;
  3857.  
  3858.             SetRasterMenu(RasterEnabled);
  3859.         }
  3860.     }
  3861.  
  3862.         /* Choose the right console data processing routine. */
  3863.  
  3864.     ConProcessUpdate();
  3865.  
  3866.         /* Reset terminal emulation. */
  3867.  
  3868.     if(Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3869.     {
  3870.         ClearCursor();
  3871.  
  3872.         ForegroundPen = GetPenIndex(SafeTextPen);
  3873.         BackgroundPen = 0;
  3874.  
  3875.         UpdatePens();
  3876.  
  3877.         Reset();
  3878.  
  3879.         DrawCursor();
  3880.     }
  3881.     else
  3882.     {
  3883.         if(XEmulatorBase)
  3884.             XEmulatorResetConsole(XEM_IO);
  3885.     }
  3886.  
  3887.         /* Restart the fast! macro panel. */
  3888.  
  3889.     if(HadFastMacros || Config -> MiscConfig -> OpenFastMacroPanel)
  3890.         OpenFastWindow();
  3891.  
  3892.     if(Config -> TerminalConfig -> UseTerminalTask && Config -> TerminalConfig -> EmulationMode != EMULATION_EXTERNAL)
  3893.         CreateEmulationProcess();
  3894.     else
  3895.         DeleteEmulationProcess();
  3896.  
  3897.     CreateLED();
  3898.  
  3899.     TTYResize();
  3900.  
  3901.     return(NULL);
  3902. }
  3903.  
  3904.     /* CloseAll():
  3905.      *
  3906.      *    Free all resources and leave the program.
  3907.      */
  3908.  
  3909. VOID __regargs
  3910. CloseAll(BYTE CloseDOS)
  3911. {
  3912.     WORD i;
  3913.  
  3914.     Forbid();
  3915.  
  3916.     if(RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name)
  3917.         RemSemaphore(&RendezvousSemaphore);
  3918.  
  3919.     Permit();
  3920.  
  3921. #ifdef DATAFEED
  3922.     {
  3923.         extern BPTR DataFeed;
  3924.  
  3925.         if(DataFeed)
  3926.         {
  3927.             Close(DataFeed);
  3928.  
  3929.             DataFeed = NULL;
  3930.         }
  3931.     }
  3932. #endif    /* DATAFEED */
  3933.  
  3934.     Forbid();
  3935.  
  3936.     if(DialMsg)
  3937.     {
  3938.         DialMsg -> rm_Result1 = RC_WARN;
  3939.         DialMsg -> rm_Result2 = 0;
  3940.  
  3941.         ReplyMsg(DialMsg);
  3942.  
  3943.         DialMsg = NULL;
  3944.     }
  3945.  
  3946.     Permit();
  3947.  
  3948.     DeleteRecord();
  3949.  
  3950.     DeleteQueueProcess();
  3951.  
  3952.     SoundExit();
  3953.  
  3954.     SZ_SizeCleanup();
  3955.  
  3956.     FreeDialList(TRUE);
  3957.  
  3958.     if(SpecialQueue)
  3959.     {
  3960.         DeleteMsgQueue(SpecialQueue);
  3961.  
  3962.         SpecialQueue = NULL;
  3963.     }
  3964.  
  3965.     if(SpecialTable)
  3966.     {
  3967.         FreeVecPooled(SpecialTable);
  3968.  
  3969.         SpecialTable = NULL;
  3970.     }
  3971.  
  3972.     if(AbortTable)
  3973.     {
  3974.         FreeVecPooled(AbortTable);
  3975.  
  3976.         AbortTable = NULL;
  3977.     }
  3978.  
  3979.     if(BackupConfig)
  3980.     {
  3981.         DeleteConfiguration(BackupConfig);
  3982.  
  3983.         BackupConfig = NULL;
  3984.     }
  3985.  
  3986.     if(IntuitionBase && Window)
  3987.         BlockWindows();
  3988.  
  3989.     /* ALWAYS */
  3990.     {
  3991.         extern struct MsgPort *RexxPort;
  3992.  
  3993.         if(RexxPort)
  3994.             RemPort(RexxPort);
  3995.     }
  3996.  
  3997.     DeleteChatGadget();
  3998.  
  3999.     if(TermRexxPort)
  4000.     {
  4001.         if(RexxSysBase)
  4002.         {
  4003.             struct Message *Msg;
  4004.  
  4005.             while(Msg = GetMsg(TermRexxPort))
  4006.                 ReplyMsg(Msg);
  4007.         }
  4008.  
  4009.         DeleteMsgPort(TermRexxPort);
  4010.  
  4011.         TermRexxPort = NULL;
  4012.     }
  4013.  
  4014.     if(RexxProcess)
  4015.     {
  4016.         Forbid();
  4017.  
  4018.         Signal(RexxProcess,SIG_KILL);
  4019.  
  4020.         ClrSignal(SIG_HANDSHAKE);
  4021.  
  4022.         Wait(SIG_HANDSHAKE);
  4023.  
  4024.         Permit();
  4025.  
  4026.         RexxProcess = NULL;
  4027.     }
  4028.  
  4029.     if(RexxSysBase)
  4030.     {
  4031.         CloseLibrary(RexxSysBase);
  4032.  
  4033.         RexxSysBase = NULL;
  4034.     }
  4035.  
  4036.     if(XprIO && XProtocolBase)
  4037.         XProtocolCleanup(XprIO);
  4038.  
  4039.     if(XProtocolBase)
  4040.     {
  4041.         CloseLibrary(XProtocolBase);
  4042.  
  4043.         XProtocolBase = NULL;
  4044.     }
  4045.  
  4046.     if(XprIO)
  4047.     {
  4048.         FreeVec(XprIO);
  4049.  
  4050.         XprIO = NULL;
  4051.     }
  4052.  
  4053.     if(CursorKeys)
  4054.     {
  4055.         FreeVecPooled(CursorKeys);
  4056.  
  4057.         CursorKeys = NULL;
  4058.     }
  4059.  
  4060.     if(MacroKeys)
  4061.     {
  4062.         FreeVecPooled(MacroKeys);
  4063.  
  4064.         MacroKeys = NULL;
  4065.     }
  4066.  
  4067.     FreeList(&ARexxQueue);
  4068.  
  4069.     TerminateBuffer();
  4070.  
  4071.     DeleteSpeech();
  4072.  
  4073.     Forbid();
  4074.  
  4075.     BufferClosed = TRUE;
  4076.  
  4077.     DeleteBuffer();
  4078.  
  4079.     Permit();
  4080.  
  4081.     if(AttentionBuffers[0])
  4082.     {
  4083.         FreeVecPooled(AttentionBuffers[0]);
  4084.  
  4085.         AttentionBuffers[0] = NULL;
  4086.     }
  4087.  
  4088.     if(SendTable)
  4089.     {
  4090.         FreeTranslationTable(SendTable);
  4091.  
  4092.         SendTable = NULL;
  4093.     }
  4094.  
  4095.     if(ReceiveTable)
  4096.     {
  4097.         FreeTranslationTable(ReceiveTable);
  4098.  
  4099.         ReceiveTable = NULL;
  4100.     }
  4101.  
  4102.     FreeDialList(TRUE);
  4103.  
  4104.     DeleteOffsetTables();
  4105.  
  4106.     FreeList(&FastMacroList);
  4107.     FreeList((struct List *)&ReviewBufferHistory);
  4108.     FreeList((struct List *)&TextBufferHistory);
  4109.  
  4110.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  4111.     {
  4112.         if(GenericListTable[i])
  4113.         {
  4114.             DeleteGenericList(GenericListTable[i]);
  4115.  
  4116.             GenericListTable[i] = NULL;
  4117.         }
  4118.     }
  4119.  
  4120.     if(FileCapture)
  4121.     {
  4122.         BufferClose(FileCapture);
  4123.  
  4124.         if(!GetFileSize(CaptureName))
  4125.             DeleteFile(CaptureName);
  4126.         else
  4127.         {
  4128.             AddProtection(CaptureName,FIBF_EXECUTE);
  4129.  
  4130.             if(Config -> MiscConfig -> CreateIcons)
  4131.                 AddIcon(CaptureName,FILETYPE_TEXT,FALSE);
  4132.         }
  4133.  
  4134.         FileCapture = NULL;
  4135.     }
  4136.  
  4137.     if(PrinterCapture)
  4138.     {
  4139.         Close(PrinterCapture);
  4140.  
  4141.         PrinterCapture = NULL;
  4142.     }
  4143.  
  4144.         /* Close the external emulator. */
  4145.  
  4146.     if(XEmulatorBase)
  4147.     {
  4148.         if(XEM_IO)
  4149.         {
  4150.             XEmulatorMacroKeyFilter(XEM_IO,NULL);
  4151.             XEmulatorCloseConsole(XEM_IO);
  4152.             XEmulatorCleanup(XEM_IO);
  4153.  
  4154.             FreeVec(XEM_IO);
  4155.  
  4156.             XEM_IO = NULL;
  4157.         }
  4158.  
  4159.         CloseLibrary(XEmulatorBase);
  4160.  
  4161.         XEmulatorBase = NULL;
  4162.     }
  4163.  
  4164.     if(XEM_MacroKeys)
  4165.     {
  4166.         FreeVecPooled(XEM_MacroKeys);
  4167.  
  4168.         XEM_MacroKeys = NULL;
  4169.     }
  4170.  
  4171.     DeleteDisplay();
  4172.  
  4173.     CaptureParserExit();
  4174.  
  4175.     if(KeySegment)
  4176.     {
  4177.         UnLoadSeg(KeySegment);
  4178.  
  4179.         KeySegment = NULL;
  4180.     }
  4181.  
  4182.     StopCall(TRUE);
  4183.  
  4184.     if(CheckBit != -1)
  4185.     {
  4186.         FreeSignal(CheckBit);
  4187.  
  4188.         CheckBit = -1;
  4189.     }
  4190.  
  4191.     ClearSerial();
  4192.  
  4193.     DeleteSerial();
  4194.  
  4195.     DeletePatternList(PatternList);
  4196.  
  4197.     if(TimeRequest)
  4198.     {
  4199.         if(TimeRequest -> tr_node . io_Device)
  4200.             CloseDevice(TimeRequest);
  4201.  
  4202.         DeleteIORequest(TimeRequest);
  4203.  
  4204.         TimeRequest = NULL;
  4205.     }
  4206.  
  4207.     if(TimePort)
  4208.     {
  4209.         DeleteMsgPort(TimePort);
  4210.  
  4211.         TimePort = NULL;
  4212.     }
  4213.  
  4214.     ShutdownCx();
  4215.  
  4216.     if(NormalColourTable)
  4217.     {
  4218.         DeleteColourTable(NormalColourTable);
  4219.  
  4220.         NormalColourTable = NULL;
  4221.     }
  4222.  
  4223.     if(BlinkColourTable)
  4224.     {
  4225.         DeleteColourTable(BlinkColourTable);
  4226.  
  4227.         BlinkColourTable = NULL;
  4228.     }
  4229.  
  4230.     if(ANSIColourTable)
  4231.     {
  4232.         DeleteColourTable(ANSIColourTable);
  4233.  
  4234.         ANSIColourTable = NULL;
  4235.     }
  4236.  
  4237.     if(EGAColourTable)
  4238.     {
  4239.         DeleteColourTable(EGAColourTable);
  4240.  
  4241.         EGAColourTable = NULL;
  4242.     }
  4243.  
  4244.     if(DefaultColourTable)
  4245.     {
  4246.         DeleteColourTable(DefaultColourTable);
  4247.  
  4248.         DefaultColourTable = NULL;
  4249.     }
  4250.  
  4251.     if(MonoColourTable)
  4252.     {
  4253.         DeleteColourTable(MonoColourTable);
  4254.  
  4255.         MonoColourTable = NULL;
  4256.     }
  4257.  
  4258.     if(TermPort)
  4259.     {
  4260.         if(TermID != -1)
  4261.         {
  4262.             ObtainSemaphore(&TermPort -> OpenSemaphore);
  4263.  
  4264.             TermPort -> OpenCount--;
  4265.  
  4266.             if(TermPort -> OpenCount <= 0 && !TermPort -> HoldIt)
  4267.             {
  4268.                 RemPort(&TermPort -> ExecNode);
  4269.  
  4270.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4271.  
  4272.                 FreeVec(TermPort);
  4273.             }
  4274.             else
  4275.                 ReleaseSemaphore(&TermPort -> OpenSemaphore);
  4276.  
  4277.             TermID = -1;
  4278.         }
  4279.  
  4280.         TermPort = NULL;
  4281.     }
  4282.  
  4283.     CloseClip();
  4284.  
  4285. //    DebugExit();
  4286.  
  4287.     if(GTLayoutBase)
  4288.     {
  4289.         CloseLibrary(GTLayoutBase);
  4290.  
  4291.         GTLayoutBase = NULL;
  4292.     }
  4293.  
  4294.     if(Config)
  4295.     {
  4296.         DeleteConfiguration(Config);
  4297.  
  4298.         Config = NULL;
  4299.     }
  4300.  
  4301.     if(PrivateConfig)
  4302.     {
  4303.         DeleteConfiguration(PrivateConfig);
  4304.  
  4305.         PrivateConfig = NULL;
  4306.     }
  4307.  
  4308.     if(FakeInputEvent)
  4309.     {
  4310.         FreeVecPooled(FakeInputEvent);
  4311.  
  4312.         FakeInputEvent = NULL;
  4313.     }
  4314.  
  4315.     if(ConsoleDevice)
  4316.     {
  4317.         CloseDevice(ConsoleRequest);
  4318.  
  4319.         ConsoleDevice = NULL;
  4320.     }
  4321.  
  4322.     if(ConsoleRequest)
  4323.     {
  4324.         FreeVecPooled(ConsoleRequest);
  4325.  
  4326.         ConsoleRequest = NULL;
  4327.     }
  4328.  
  4329.     if(IconBase)
  4330.     {
  4331.         CloseLibrary(IconBase);
  4332.  
  4333.         IconBase = NULL;
  4334.     }
  4335.  
  4336.     if(DataTypesBase)
  4337.     {
  4338.         CloseLibrary(DataTypesBase);
  4339.  
  4340.         DataTypesBase = NULL;
  4341.     }
  4342.  
  4343.     if(WorkbenchBase)
  4344.     {
  4345.         CloseLibrary(WorkbenchBase);
  4346.  
  4347.         WorkbenchBase = NULL;
  4348.     }
  4349.  
  4350.     if(OwnDevUnitBase)
  4351.     {
  4352.         CloseLibrary(OwnDevUnitBase);
  4353.  
  4354.         OwnDevUnitBase = NULL;
  4355.     }
  4356.  
  4357.     if(CxBase)
  4358.     {
  4359.         CloseLibrary(CxBase);
  4360.  
  4361.         CxBase = NULL;
  4362.     }
  4363.  
  4364.     if(IFFParseBase)
  4365.     {
  4366.         CloseLibrary(IFFParseBase);
  4367.  
  4368.         IFFParseBase = NULL;
  4369.     }
  4370.  
  4371.     if(AslBase)
  4372.     {
  4373.         CloseLibrary(AslBase);
  4374.  
  4375.         AslBase = NULL;
  4376.     }
  4377.  
  4378.     if(DiskfontBase)
  4379.     {
  4380.         CloseLibrary(DiskfontBase);
  4381.  
  4382.         DiskfontBase = NULL;
  4383.     }
  4384.  
  4385.     if(GadToolsBase)
  4386.     {
  4387.         CloseLibrary(GadToolsBase);
  4388.  
  4389.         GadToolsBase = NULL;
  4390.     }
  4391.  
  4392.     if(LayersBase)
  4393.     {
  4394.         CloseLibrary(LayersBase);
  4395.  
  4396.         LayersBase = NULL;
  4397.     }
  4398.  
  4399.     if(GfxBase)
  4400.     {
  4401.         CloseLibrary(GfxBase);
  4402.  
  4403.         GfxBase = NULL;
  4404.     }
  4405.  
  4406.     if(IntuitionBase)
  4407.     {
  4408.         CloseLibrary(IntuitionBase);
  4409.  
  4410.         IntuitionBase = NULL;
  4411.     }
  4412.  
  4413.     LocaleClose();
  4414.  
  4415.     if(UtilityBase)
  4416.     {
  4417.         CloseLibrary(UtilityBase);
  4418.  
  4419.         UtilityBase = NULL;
  4420.     }
  4421.  
  4422. #ifdef DEBUG
  4423.     DebugExit();
  4424. #endif    /* DEBUG */
  4425.  
  4426.     MemoryCleanup();
  4427.  
  4428.     if(WBenchMsg)
  4429.     {
  4430.         CurrentDir(WBenchLock);
  4431.  
  4432.         if(DOSBase)
  4433.         {
  4434.             CloseLibrary(DOSBase);
  4435.  
  4436.             DOSBase = NULL;
  4437.         }
  4438.  
  4439.         Forbid();
  4440.  
  4441.         ReplyMsg((struct Message *)WBenchMsg);
  4442.  
  4443.         WBenchMsg = NULL;
  4444.     }
  4445.     else
  4446.     {
  4447.         if(CloseDOS && DOSBase)
  4448.         {
  4449.             CloseLibrary(DOSBase);
  4450.  
  4451.             DOSBase = NULL;
  4452.         }
  4453.     }
  4454. }
  4455.  
  4456.     /* AddExtraAssignment(STRPTR LocalDir,STRPTR Assign):
  4457.      *
  4458.      *    Add assignments for local directories.
  4459.      */
  4460.  
  4461. STATIC VOID __regargs
  4462. AddExtraAssignment(STRPTR LocalDir,STRPTR Assign)
  4463. {
  4464.     UBYTE    LocalBuffer[40];
  4465.     BPTR    FileLock;
  4466.  
  4467.         // Add the colon, we'll need it later
  4468.  
  4469.     SPrintf(LocalBuffer,"%s:",Assign);
  4470.  
  4471.         // Is the local directory present?
  4472.  
  4473.     if(FileLock = Lock(LocalDir,ACCESS_READ))
  4474.     {
  4475.             // Is the assignment present?
  4476.  
  4477.         if(IsAssign(LocalBuffer))
  4478.         {
  4479.                 // Check to see if the local directory
  4480.                 // is already on the assignment list
  4481.  
  4482.             if(LockInAssign(FileLock,LocalBuffer))
  4483.             {
  4484.                 UnLock(FileLock);
  4485.  
  4486.                 FileLock = NULL;
  4487.             }
  4488.         }
  4489.     }
  4490.  
  4491.         // Can we attach the lock to the assignment list?
  4492.  
  4493.     if(FileLock)
  4494.     {
  4495.         Forbid();
  4496.  
  4497.             // If the assignment is already present, add the
  4498.             // new directory, else create a new assignment.
  4499.  
  4500.         if(IsAssign(LocalBuffer))
  4501.             AssignAdd(Assign,FileLock);
  4502.         else
  4503.             AssignLock(Assign,FileLock);
  4504.  
  4505.         Permit();
  4506.     }
  4507. }
  4508.  
  4509.     /* OpenAll():
  4510.      *
  4511.      *    Open all required resources or return an error message
  4512.      *    if anything went wrong.
  4513.      */
  4514.  
  4515. STRPTR __regargs
  4516. OpenAll(STRPTR ConfigPath)
  4517. {
  4518.     UBYTE    PathBuffer[MAX_FILENAME_LENGTH];
  4519.     STRPTR    Result,Error,ConfigFileName = NULL;
  4520.     WORD    i;
  4521.     LONG    ErrorCode;
  4522.  
  4523.         /* Pretty cheap ;-) */
  4524.  
  4525.     Kick30 = (SysBase -> LibNode . lib_Version >= 39);
  4526.  
  4527.     if(!MemorySetup())
  4528.         return("Cannot create memory pool");
  4529.  
  4530. #ifdef DEBUG
  4531.     DebugInit();
  4532. #endif    /* DEBUG */
  4533.  
  4534.         /* Don't let it hit the ground! */
  4535.  
  4536.     ConTransfer = ConProcess;
  4537.  
  4538.         /* Remember the start of this session. */
  4539.  
  4540.     DateStamp(&SessionStart);
  4541.  
  4542.         /* Reset some flags. */
  4543.  
  4544.     BinaryTransfer    = TRUE;
  4545.  
  4546.     Status        = STATUS_READY;
  4547.  
  4548.     WasOnline    = FALSE;
  4549.     Online        = FALSE;
  4550.  
  4551.     InSequence    = FALSE;
  4552.     Quiet        = FALSE;
  4553.  
  4554.     TagDPI[0] . ti_Tag = TAG_DONE;
  4555.  
  4556.         /* Double buffered file locking. */
  4557.  
  4558.     NewList(&DoubleBufferList);
  4559.  
  4560.     InitSemaphore(&DoubleBufferSemaphore);
  4561.  
  4562.         /* ARexx command queue. */
  4563.  
  4564.     InitSemaphore(&ARexxQueueSemaphore);
  4565.  
  4566.     NewList(&ARexxQueue);
  4567.  
  4568.         /* Terminal emulation data. */
  4569.  
  4570.     InitSemaphore(&TerminalSemaphore);
  4571.  
  4572.         /* Phone number patterns and rates. */
  4573.  
  4574.     InitSemaphore(&PatternSemaphore);
  4575.  
  4576.         /* Online status. */
  4577.  
  4578.     InitSemaphore(&OnlineSemaphore);
  4579.  
  4580.         /* Text buffer task access semaphore. */
  4581.  
  4582.     InitSemaphore(&BufferTaskSemaphore);
  4583.     InitSemaphore(&ReviewTaskSemaphore);
  4584.  
  4585.         /* Set up all the lists. */
  4586.  
  4587.     NewList(&PacketHistoryList);
  4588.     NewList(&EmptyList);
  4589.     NewList(&FastMacroList);
  4590.     NewList(&TransferInfoList);
  4591.     NewList((struct List *)&PhoneGroupList);
  4592.  
  4593.     NewList((struct List *)&ReviewBufferHistory);
  4594.     NewList((struct List *)&TextBufferHistory);
  4595.  
  4596.         /* Rendezvous setup. */
  4597.  
  4598.     InitSemaphore(&RendezvousSemaphore);
  4599.  
  4600.     RendezvousSemaphore . rs_Login        = RendezvousLogin;
  4601.     RendezvousSemaphore . rs_Logoff        = RendezvousLogoff;
  4602.     RendezvousSemaphore . rs_NewNode    = RendezvousNewNode;
  4603.  
  4604.         /* Open the translation tables. */
  4605.  
  4606.     LocaleOpen("term.catalog","english",20);
  4607.  
  4608.         /* Fill in the menu configuration. */
  4609.  
  4610.     LocalizeMenuTable(TermMenu,MenuLabels);
  4611.  
  4612.         /* Open intuition.library, any version. */
  4613.  
  4614.     if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  4615.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_INTUITION_LIBRARY_TXT));
  4616.  
  4617.     Forbid();
  4618.  
  4619.         /* Query the current public screen modes. */
  4620.  
  4621.     PublicModes = SetPubScreenModes(NULL);
  4622.  
  4623.         /* Set them back. */
  4624.  
  4625.     SetPubScreenModes(PublicModes);
  4626.  
  4627.     Permit();
  4628.  
  4629.         /* Check if we should use the old style sliders. */
  4630.  
  4631.     if(GetVar("termoldsliders",PathBuffer,256,NULL) >= 0)
  4632.         SliderType = SLIDER_KIND;
  4633.     else
  4634.         SliderType = LEVEL_KIND;
  4635.  
  4636.         /* Open some more libraries. */
  4637.  
  4638.     if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0)))
  4639.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GRAPHICS_LIBRARY_TXT));
  4640.  
  4641.     if(!(LayersBase = OpenLibrary("layers.library",0)))
  4642.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_LAYERS_LIBRARY_TXT));
  4643.  
  4644.         /* Install the correct routines to query
  4645.          * the rendering colours and drawing mode.
  4646.          */
  4647.  
  4648.     if(!Kick30)
  4649.     {
  4650.         ReadAPen = OldGetAPen;
  4651.         ReadBPen = OldGetBPen;
  4652.         ReadDrMd = OldGetDrMd;
  4653.         SetMask = OldSetWrMsk;
  4654.     }
  4655.     else
  4656.     {
  4657.         ReadAPen = NewGetAPen;
  4658.         ReadBPen = NewGetBPen;
  4659.         ReadDrMd = NewGetDrMd;
  4660.         SetMask = NewSetWrMsk;
  4661.     }
  4662.  
  4663.         /* Check if locale.library has already installed the operating system
  4664.          * patches required for localization.
  4665.          */
  4666.  
  4667.     LanguageCheck();
  4668.  
  4669.         /* Open the remaining libraries. */
  4670.  
  4671.     if(!(GadToolsBase = OpenLibrary("gadtools.library",0)))
  4672.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GADTOOLS_LIBRARY_TXT));
  4673.  
  4674.     if(!(AslBase = OpenLibrary("asl.library",0)))
  4675.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_ASL_LIBRARY_TXT));
  4676.  
  4677.     if(!(IFFParseBase = OpenLibrary("iffparse.library",0)))
  4678.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_IFFPARSE_LIBRARY_TXT));
  4679.  
  4680.     if(!(CxBase = OpenLibrary("commodities.library",0)))
  4681.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_COMMODITIES_LIBRARY_TXT));
  4682.  
  4683.     if(!(DiskfontBase = (struct Library *)OpenLibrary("diskfont.library",0)))
  4684.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_DISKFONT_LIBRARY_TXT));
  4685.  
  4686.         /* User interface. */
  4687.  
  4688.     if(!(GTLayoutBase = SafeOpenLibrary("PROGDIR:gtlayout.library",24)))
  4689.     {
  4690.         if(!(GTLayoutBase = SafeOpenLibrary("gtlayout.library",24)))
  4691.             return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_GTLAYOUT_LIBRARY_TXT));
  4692.     }
  4693.  
  4694.     if(GetVar("termoldcycle",PathBuffer,256,NULL) >= 0 || GetVar("RussLeBar",PathBuffer,256,NULL) >= 0)
  4695.     {
  4696.         LONG Value;
  4697.  
  4698.         CycleType = CYCLE_KIND;
  4699.  
  4700.         if(StrToLong(PathBuffer,&Value) > 0)
  4701.         {
  4702.             if(!Value && GTLayoutBase -> lib_Version >= 22)
  4703.                 CycleType = POPUP_KIND;
  4704.         }
  4705.     }
  4706.     else
  4707.     {
  4708.         if(GTLayoutBase -> lib_Version >= 22)
  4709.             CycleType = POPUP_KIND;
  4710.         else
  4711.             CycleType = CYCLE_KIND;
  4712.     }
  4713.  
  4714.         /* Open OwnDevUnit.library, don't complain if it fails. */
  4715.  
  4716.     OwnDevUnitBase = OpenLibrary(ODU_NAME,0);
  4717.  
  4718.         /* Open workbench.library, don't complain if it fails. */
  4719.  
  4720.     WorkbenchBase = OpenLibrary("workbench.library",0);
  4721.  
  4722.         /* Open icon.library as well, don't complain if it fails either. */
  4723.  
  4724.     IconBase = OpenLibrary("icon.library",0);
  4725.  
  4726.         /* Try to open datatypes.library, just for the fun of it. */
  4727.  
  4728.     DataTypesBase = OpenLibrary("datatypes.library",39);
  4729.  
  4730.     if(!(ConsoleRequest = (struct IOStdReq *)AllocVecPooled(sizeof(struct IOStdReq),MEMF_ANY|MEMF_CLEAR)))
  4731.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CONSOLE_REQUEST_TXT));
  4732.  
  4733.     if(OpenDevice("console.device",CONU_LIBRARY,ConsoleRequest,0))
  4734.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_CONSOLE_DEVICE_TXT));
  4735.  
  4736.     ConsoleDevice = &ConsoleRequest -> io_Device -> dd_Library;
  4737.  
  4738.     if(!(FakeInputEvent = (struct InputEvent *)AllocVecPooled(sizeof(struct InputEvent),MEMF_ANY|MEMF_CLEAR)))
  4739.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_INPUTEVENT_TXT));
  4740.  
  4741.     FakeInputEvent -> ie_Class = IECLASS_RAWKEY;
  4742.  
  4743.     if(!(MacroKeys = (struct MacroKeys *)AllocVecPooled(sizeof(struct MacroKeys),MEMF_ANY|MEMF_CLEAR)))
  4744.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACROKEYS_TXT));
  4745.  
  4746.     if(!(CursorKeys = (struct CursorKeys *)AllocVecPooled(sizeof(struct CursorKeys),MEMF_ANY|MEMF_CLEAR)))
  4747.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_CURSORKEYS_TXT));
  4748.  
  4749.     ResetCursorKeys(CursorKeys);
  4750.  
  4751.         /* Add extra assignments. */
  4752.  
  4753.     AddExtraAssignment("PROGDIR:Fonts","Fonts");
  4754.     AddExtraAssignment("Fonts","Fonts");
  4755.     AddExtraAssignment("PROGDIR:Libs","Libs");
  4756.     AddExtraAssignment("Libs","Libs");
  4757.  
  4758.         /* Set up the attention buffers. */
  4759.  
  4760.     if(!(AttentionBuffers[0] = (STRPTR)AllocVecPooled(SCAN_COUNT * 260,MEMF_ANY|MEMF_CLEAR)))
  4761.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_SEQUENCE_ATTENTION_INFO_TXT));
  4762.  
  4763.     for(i = 1 ; i < SCAN_COUNT ; i++)
  4764.         AttentionBuffers[i] = &AttentionBuffers[i - 1][260];
  4765.  
  4766.         /* Obtain the default environment storage
  4767.          * path.
  4768.          */
  4769.  
  4770.     if(!ConfigPath)
  4771.     {
  4772.         ConfigPath = PathBuffer;
  4773.  
  4774.         if(!GetEnvDOS("TERMCONFIGPATH",PathBuffer))
  4775.         {
  4776.             if(!GetEnvDOS("TERMPATH",PathBuffer))
  4777.             {
  4778.                 APTR LastPtr = ThisProcess -> pr_WindowPtr;
  4779.                 BPTR FileLock;
  4780.  
  4781.                 strcpy(PathBuffer,"TERM:config");
  4782.  
  4783.                 ThisProcess -> pr_WindowPtr = (APTR)-1;
  4784.  
  4785.                 if(FileLock = Lock("TERM:",ACCESS_READ))
  4786.                     UnLock(FileLock);
  4787.                 else
  4788.                 {
  4789.                     FileLock = DupLock(ThisProcess-> pr_HomeDir);
  4790.  
  4791.                         /* Create TERM: assignment referring to
  4792.                          * the directory `term' was loaded from.
  4793.                          */
  4794.  
  4795.                     if(!AssignLock("TERM",FileLock))
  4796.                         UnLock(FileLock);
  4797.                 }
  4798.  
  4799.                 if(!(FileLock = Lock(PathBuffer,ACCESS_READ)))
  4800.                     FileLock = CreateDir(PathBuffer);
  4801.  
  4802.                 if(FileLock)
  4803.                     UnLock(FileLock);
  4804.  
  4805.                 ThisProcess -> pr_WindowPtr = LastPtr;
  4806.             }
  4807.         }
  4808.     }
  4809.     else
  4810.     {
  4811.         if(GetFileSize(ConfigPath))
  4812.         {
  4813.             STRPTR Index;
  4814.  
  4815.             strcpy(PathBuffer,ConfigPath);
  4816.  
  4817.             Index = PathPart(PathBuffer);
  4818.  
  4819.             *Index = 0;
  4820.  
  4821.             ConfigFileName = ConfigPath;
  4822.  
  4823.             ConfigPath = PathBuffer;
  4824.         }
  4825.     }
  4826.  
  4827.         /* Check for proper assignment path if necessary. */
  4828.  
  4829.         if(!Strnicmp(ConfigPath,"TERM:",5))
  4830.         {
  4831.             APTR OldPtr = ThisProcess -> pr_WindowPtr;
  4832.             BPTR DirLock;
  4833.  
  4834.             /* Block dos requesters. */
  4835.  
  4836.             ThisProcess -> pr_WindowPtr = (APTR)-1;
  4837.  
  4838.             /* Try to get a lock on `TERM:' assignment. */
  4839.  
  4840.         if(DirLock = Lock("TERM:",ACCESS_READ))
  4841.             UnLock(DirLock);
  4842.         else
  4843.         {
  4844.                 /* Clone current directory lock. */
  4845.  
  4846.             DirLock = DupLock(ThisProcess-> pr_CurrentDir);
  4847.  
  4848.                 /* Create TERM: assignment referring to
  4849.                  * current directory.
  4850.                  */
  4851.  
  4852.             if(!AssignLock("TERM",DirLock))
  4853.                 UnLock(DirLock);
  4854.         }
  4855.  
  4856.         ThisProcess -> pr_WindowPtr = OldPtr;
  4857.         }
  4858.  
  4859.         /* Create proper path names. */
  4860.  
  4861.     if(ConfigFileName)
  4862.     {
  4863.         if(!GetFileSize(ConfigFileName))
  4864.             ConfigFileName = NULL;
  4865.     }
  4866.  
  4867.     if(!ConfigFileName)
  4868.     {
  4869.         strcpy(LastConfig,ConfigPath);
  4870.  
  4871.         AddPart(LastConfig,"term_preferences.iff",MAX_FILENAME_LENGTH);
  4872.  
  4873.         if(!GetFileSize(LastConfig))
  4874.         {
  4875.             strcpy(LastConfig,ConfigPath);
  4876.  
  4877.             AddPart(LastConfig,"term.prefs",MAX_FILENAME_LENGTH);
  4878.         }
  4879.     }
  4880.     else
  4881.         strcpy(LastConfig,ConfigFileName);
  4882.  
  4883.     strcpy(DefaultPubScreenName,"Workbench");
  4884.  
  4885.         /* Create both configuration buffers. */
  4886.  
  4887.     if(!(Config = CreateConfiguration(TRUE)))
  4888.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_PRIMARY_CONFIG_TXT));
  4889.  
  4890.     if(!(PrivateConfig = CreateConfiguration(TRUE)))
  4891.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_SECONDARY_CONFIG_TXT));
  4892.  
  4893.     ResetConfig(Config,ConfigPath);
  4894.  
  4895.         /* Read some more environment variables. */
  4896.  
  4897.     if(!WindowName[0])
  4898.     {
  4899.         if(!GetEnvDOS("TERMWINDOW",WindowName))
  4900.             strcpy(WindowName,"CON:0/11//100/term Output Window/CLOSE/SCREEN %s");
  4901.     }
  4902.  
  4903.     GetEnvDOS("EDITOR",Config -> PathConfig -> Editor);
  4904.  
  4905.         /* Look for the default configuration file. */
  4906.  
  4907.     if(!ReadConfig(LastConfig,Config))
  4908.     {
  4909.         ResetConfig(Config,ConfigPath);
  4910.  
  4911.         Initializing = TRUE;
  4912.  
  4913.         LoadColours = TRUE;
  4914.  
  4915.             // Now we can safely assume that this is the
  4916.             // first invocation of this program on the
  4917.             // current setup
  4918.  
  4919.         FirstInvocation = TRUE;
  4920.     }
  4921.     else
  4922.     {
  4923.         Current2DefaultPalette(Config);
  4924.  
  4925.         if(Config -> ScreenConfig -> ColourMode == COLOUR_AMIGA)
  4926.             Initializing = FALSE;
  4927.         else
  4928.             Initializing = TRUE;
  4929.     }
  4930.  
  4931.     if(UseNewDevice)
  4932.         strcpy(Config -> SerialConfig -> SerialDevice,NewDevice);
  4933.  
  4934.     if(UseNewUnit)
  4935.         Config -> SerialConfig -> UnitNumber = NewUnit;
  4936.  
  4937.     if(Config -> MiscConfig -> OpenFastMacroPanel)
  4938.         HadFastMacros = TRUE;
  4939.  
  4940.     if(!LastPhone[0])
  4941.     {
  4942.         strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4943.         AddPart(LastPhone,    "term_phonebook.iff",MAX_FILENAME_LENGTH);
  4944.  
  4945.         if(!GetFileSize(LastPhone))
  4946.         {
  4947.             strcpy(LastPhone,    Config -> PathConfig -> DefaultStorage);
  4948.             AddPart(LastPhone,    "phonebook.prefs",MAX_FILENAME_LENGTH);
  4949.         }
  4950.     }
  4951.  
  4952.     strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4953.     AddPart(LastKeys,    "term_hotkeys.iff",MAX_FILENAME_LENGTH);
  4954.  
  4955.     if(!GetFileSize(LastKeys))
  4956.     {
  4957.         strcpy(LastKeys,    Config -> PathConfig -> DefaultStorage);
  4958.         AddPart(LastKeys,    "hotkeys.prefs",MAX_FILENAME_LENGTH);
  4959.     }
  4960.  
  4961.     strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4962.     AddPart(LastSpeech,    "term_speech.iff",MAX_FILENAME_LENGTH);
  4963.  
  4964.     if(!GetFileSize(LastSpeech))
  4965.     {
  4966.         strcpy(LastSpeech,    Config -> PathConfig -> DefaultStorage);
  4967.         AddPart(LastSpeech,    "speech.prefs",MAX_FILENAME_LENGTH);
  4968.     }
  4969.  
  4970.     strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4971.     AddPart(LastFastMacros,    "term_fastmacros.iff",MAX_FILENAME_LENGTH);
  4972.  
  4973.     if(!GetFileSize(LastFastMacros))
  4974.     {
  4975.         strcpy(LastFastMacros,    Config -> PathConfig -> DefaultStorage);
  4976.         AddPart(LastFastMacros,    "fastmacros.prefs",MAX_FILENAME_LENGTH);
  4977.     }
  4978.  
  4979.     if(Config -> MacroFileName[0])
  4980.         strcpy(LastMacros,Config -> MacroFileName);
  4981.     else
  4982.     {
  4983.         strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4984.         AddPart(LastMacros,    "term_macros.iff",MAX_FILENAME_LENGTH);
  4985.  
  4986.         if(!GetFileSize(LastMacros))
  4987.         {
  4988.             strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4989.             AddPart(LastMacros,    "macros.prefs",MAX_FILENAME_LENGTH);
  4990.  
  4991.             if(!GetFileSize(LastMacros))
  4992.             {
  4993.                 strcpy(LastMacros,    Config -> PathConfig -> DefaultStorage);
  4994.                 AddPart(LastMacros,    "functionkeys.prefs",MAX_FILENAME_LENGTH);
  4995.             }
  4996.         }
  4997.     }
  4998.  
  4999.         /* Load the keyboard macros. */
  5000.  
  5001.     if(!LoadMacros(LastMacros,MacroKeys))
  5002.         ResetMacroKeys(MacroKeys);
  5003.  
  5004.     if(Config -> CursorFileName[0])
  5005.         strcpy(LastCursorKeys,Config -> CursorFileName);
  5006.     else
  5007.     {
  5008.         strcpy(LastCursorKeys,    Config -> PathConfig -> DefaultStorage);
  5009.         AddPart(LastCursorKeys,    "cursorkeys.prefs",MAX_FILENAME_LENGTH);
  5010.     }
  5011.  
  5012.         /* Load the cursor keys. */
  5013.  
  5014.     if(!ReadIFFData(LastCursorKeys,CursorKeys,sizeof(struct CursorKeys),ID_KEYS))
  5015.         ResetCursorKeys(CursorKeys);
  5016.  
  5017.     strcpy(LastSound,    Config -> PathConfig -> DefaultStorage);
  5018.     AddPart(LastSound,    "sound.prefs",MAX_FILENAME_LENGTH);
  5019.  
  5020.         /* Load the sound settings. */
  5021.  
  5022.     memset(&SoundConfig,0,sizeof(struct SoundConfig));
  5023.  
  5024.     SoundConfig . Volume = 100;
  5025.  
  5026.     if(!ReadIFFData(LastSound,&SoundConfig,sizeof(struct SoundConfig),ID_SOUN))
  5027.         strcpy(SoundConfig . BellFile,Config -> TerminalConfig -> BeepFileName);
  5028.  
  5029.         /* Initialize the sound support routines. */
  5030.  
  5031.     SoundInit();
  5032.  
  5033.         /* Load the phone number pattern / rates settings. */
  5034.  
  5035.     strcpy(LastPattern,    Config -> PathConfig -> DefaultStorage);
  5036.     AddPart(LastPattern,    "rates.prefs",MAX_FILENAME_LENGTH);
  5037.  
  5038.     if(!(PatternList = LoadTimeDateList(LastPattern,&ErrorCode)))
  5039.     {
  5040.         if(!(PatternList = (struct List *)AllocVecPooled(sizeof(struct List),MEMF_ANY)))
  5041.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  5042.         else
  5043.             NewList(PatternList);
  5044.     }
  5045.  
  5046.         /* Are we to load the translation tables? */
  5047.  
  5048.     strcpy(LastTranslation,Config -> TranslationFileName);
  5049.  
  5050.     if(Config -> TranslationFileName[0])
  5051.     {
  5052.         if(SendTable = AllocTranslationTable())
  5053.         {
  5054.             if(ReceiveTable = AllocTranslationTable())
  5055.             {
  5056.                 if(!LoadTranslationTables(Config -> TranslationFileName,SendTable,ReceiveTable))
  5057.                 {
  5058.                     FreeTranslationTable(SendTable);
  5059.  
  5060.                     SendTable = NULL;
  5061.  
  5062.                     FreeTranslationTable(ReceiveTable);
  5063.  
  5064.                     ReceiveTable = NULL;
  5065.                 }
  5066.                 else
  5067.                 {
  5068.                     if(IsStandardTable(SendTable) && IsStandardTable(ReceiveTable))
  5069.                     {
  5070.                         FreeTranslationTable(SendTable);
  5071.  
  5072.                         SendTable = NULL;
  5073.  
  5074.                         FreeTranslationTable(ReceiveTable);
  5075.  
  5076.                         ReceiveTable = NULL;
  5077.                     }
  5078.                 }
  5079.             }
  5080.             else
  5081.             {
  5082.                 FreeTranslationTable(SendTable);
  5083.  
  5084.                 SendTable = NULL;
  5085.             }
  5086.         }
  5087.     }
  5088.  
  5089.     SendSetup();
  5090.  
  5091.         /* Set up the capture parser. */
  5092.  
  5093.     if(!CaptureParserInit())
  5094.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  5095.  
  5096.         /* Are we to freeze the text buffer? */
  5097.  
  5098.     if(!Config -> CaptureConfig -> BufferEnabled)
  5099.         BufferFrozen = TRUE;
  5100.  
  5101.     ConOutputUpdate();
  5102.  
  5103.         /* Load the fast! macro settings. */
  5104.  
  5105.     LoadFastMacros(LastFastMacros,&FastMacroList);
  5106.  
  5107.         /* Load the speech settings. */
  5108.  
  5109.     if(!ReadIFFData(LastSpeech,&SpeechConfig,sizeof(struct SpeechConfig),ID_SPEK))
  5110.     {
  5111.         SpeechConfig . Rate        = DEFRATE;
  5112.         SpeechConfig . Pitch        = DEFPITCH;
  5113.         SpeechConfig . Frequency    = DEFFREQ;
  5114.         SpeechConfig . Volume        = DEFVOL;
  5115.         SpeechConfig . Sex        = DEFSEX;
  5116.         SpeechConfig . Enabled        = FALSE;
  5117.     }
  5118.  
  5119.         /* Load the hotkey settings. */
  5120.  
  5121.     if(!LoadHotkeys(LastKeys,&Hotkeys))
  5122.     {
  5123.         strcpy(Hotkeys . termScreenToFront,    "lshift rshift return");
  5124.         strcpy(Hotkeys . BufferScreenToFront,    "control rshift return");
  5125.         strcpy(Hotkeys . SkipDialEntry,        "control lshift rshift return");
  5126.         strcpy(Hotkeys . AbortARexx,        "lshift rshift escape");
  5127.  
  5128.         Hotkeys . CommodityPriority    = 0;
  5129.         Hotkeys . HotkeysEnabled    = TRUE;
  5130.     }
  5131.  
  5132.         /* Initialize the data flow parser. */
  5133.  
  5134.     FlowInit(TRUE);
  5135.  
  5136.         /* Set up parsing jump tables. */
  5137.  
  5138.     if(!(SpecialTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_CLEAR | MEMF_ANY)))
  5139.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  5140.  
  5141.     for(i = 0 ; i < sizeof(SpecialKeys) / sizeof(struct SpecialKey) ; i++)
  5142.         SpecialTable[SpecialKeys[i] . Key] = (JUMP)SpecialKeys[i] . Routine;
  5143.  
  5144.     if(!(AbortTable = (JUMP *)AllocVecPooled(256 * sizeof(JUMP),MEMF_ANY)))
  5145.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  5146.  
  5147.     for(i = 0 ; i < 256 ; i++)
  5148.     {
  5149.         switch(AbortMap[i])
  5150.         {
  5151.             case 0:    AbortTable[i] = (JUMP)ParseCode;
  5152.                 break;
  5153.  
  5154.             case 1:    AbortTable[i] = (JUMP)DoCancel;
  5155.                 break;
  5156.  
  5157.             case 2:    AbortTable[i] = (JUMP)DoNewEsc;
  5158.                 break;
  5159.  
  5160.             case 3:    AbortTable[i] = (JUMP)DoNewCsi;
  5161.                 break;
  5162.         }
  5163.     }
  5164.  
  5165.         /* Create all generic lists. */
  5166.  
  5167.     for(i = GLIST_UPLOAD ; i < GLIST_COUNT ; i++)
  5168.     {
  5169.         if(!(GenericListTable[i] = CreateGenericList()))
  5170.             return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  5171.     }
  5172.  
  5173.         /* Load the trap settings. */
  5174.  
  5175.     strcpy(LastTraps,    Config -> PathConfig -> DefaultStorage);
  5176.     AddPart(LastTraps,    "trap.prefs",MAX_FILENAME_LENGTH);
  5177.  
  5178.     WatchTraps = TRUE;
  5179.  
  5180.     LoadTraps(LastTraps,GenericListTable[GLIST_TRAP]);
  5181.  
  5182.         /* Create the special event queue. */
  5183.  
  5184.     if(!(SpecialQueue = CreateMsgQueue(NULL,0)))
  5185.         return(LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT));
  5186.  
  5187.         /* Set up the serial driver. */
  5188.  
  5189.     if(Error = CreateSerial())
  5190.     {
  5191.         MyEasyRequest(NULL,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
  5192.  
  5193.         DeleteSerial();
  5194.     }
  5195.     else
  5196.     {
  5197.         if(SerialMessage)
  5198.         {
  5199.             MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
  5200.  
  5201.             SerialMessage = NULL;
  5202.         }
  5203.     }
  5204.  
  5205.         /* Get a signal bit. */
  5206.  
  5207.     if((CheckBit = AllocSignal(-1)) == -1)
  5208.         return(LocaleString(MSG_TERMINIT_FAILED_TO_GET_CHECK_SIGNAL_TXT));
  5209.  
  5210.     if(!(TimePort = (struct MsgPort *)CreateMsgPort()))
  5211.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  5212.  
  5213.     if(!(TimeRequest = (struct timerequest *)CreateIORequest(TimePort,sizeof(struct timerequest))))
  5214.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_IOREQUEST_TXT));
  5215.  
  5216.     if(OpenDevice("timer.device",UNIT_VBLANK,TimeRequest,0))
  5217.         return(LocaleString(MSG_TERMINIT_FAILED_TO_OPEN_TIMER_DEVICE_TXT));
  5218.  
  5219.     TimerBase = &TimeRequest -> tr_node . io_Device -> dd_Library;
  5220.  
  5221.         /* Add the global term port. */
  5222.  
  5223.     if(!TermPort)
  5224.     {
  5225.         if(!(TermPort = (struct TermPort *)AllocVec(sizeof(struct TermPort) + 11,MEMF_PUBLIC|MEMF_CLEAR)))
  5226.             return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_GLOBAL_PORT_TXT));
  5227.         else
  5228.         {
  5229.             NewList(&TermPort -> ExecNode . mp_MsgList);
  5230.  
  5231.             InitSemaphore(&TermPort -> OpenSemaphore);
  5232.  
  5233.             TermPort -> ExecNode . mp_Flags            = PA_IGNORE;
  5234.             TermPort -> ExecNode . mp_Node . ln_Name    = (char *)(TermPort + 1);
  5235.  
  5236.             strcpy(TermPort -> ExecNode . mp_Node . ln_Name,"term Port");
  5237.  
  5238.             AddPort(&TermPort -> ExecNode);
  5239.         }
  5240.     }
  5241.  
  5242.         /* Keep another term task from removing the port. */
  5243.  
  5244.     TermPort -> HoldIt = TRUE;
  5245.  
  5246.         /* Install a new term process. */
  5247.  
  5248.     ObtainSemaphore(&TermPort -> OpenSemaphore);
  5249.  
  5250.     TermPort -> OpenCount++;
  5251.  
  5252.     TermPort -> HoldIt = FALSE;
  5253.  
  5254.     TermID = TermPort -> ID++;
  5255.  
  5256.     ReleaseSemaphore(&TermPort -> OpenSemaphore);
  5257.  
  5258.         /* Set up the ID string. */
  5259.  
  5260.     if(TermID)
  5261.         SPrintf(TermIDString,"TERM.%ld",TermID);
  5262.     else
  5263.         strcpy(TermIDString,"TERM");
  5264.  
  5265.     if(RexxPortName[0])
  5266.     {
  5267.         WORD i;
  5268.  
  5269.         for(i = 0 ; i < strlen(RexxPortName) ; i++)
  5270.             RexxPortName[i] = ToUpper(RexxPortName[i]);
  5271.  
  5272.         if(FindPort(RexxPortName))
  5273.             RexxPortName[0] = 0;
  5274.     }
  5275.  
  5276.     if(!RexxPortName[0])
  5277.         strcpy(RexxPortName,TermIDString);
  5278.  
  5279.         /* Install the hotkey handler. */
  5280.  
  5281.     SetupCx();
  5282.  
  5283.         /* Allocate the first few lines for the display buffer. */
  5284.  
  5285.     if(!CreateBuffer())
  5286.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_VIEW_BUFFER_TXT));
  5287.  
  5288.     if(!(XprIO = (struct XPR_IO *)AllocVec(sizeof(struct XPR_IO),MEMF_ANY|MEMF_CLEAR)))
  5289.         return(LocaleString(MSG_TERMINIT_FAILED_TO_CREATE_PROTOCOL_BUFFER_TXT));
  5290.  
  5291.         /* Set up the external emulation macro data. */
  5292.  
  5293.     if(!(XEM_MacroKeys = (struct XEmulatorMacroKey *)AllocVecPooled((2 + 10 * 4) * sizeof(struct XEmulatorMacroKey),MEMF_ANY|MEMF_CLEAR)))
  5294.         return(LocaleString(MSG_TERMINIT_FAILED_TO_ALLOCATE_MACRO_KEY_DATA_TXT));
  5295.  
  5296.     strcpy(LastXprLibrary,Config -> TransferConfig -> DefaultLibrary);
  5297.  
  5298.     ProtocolSetup(FALSE);
  5299.  
  5300.         /* Load a keymap file if required. */
  5301.  
  5302.     if(Config -> TerminalConfig -> KeyMapFileName[0])
  5303.         KeyMap = LoadKeyMap(Config -> TerminalConfig -> KeyMapFileName);
  5304.  
  5305.     if(!(TermRexxPort = (struct MsgPort *)CreateMsgPort()))
  5306.         return(LocaleString(MSG_GLOBAL_FAILED_TO_CREATE_MSGPORT_TXT));
  5307.  
  5308.         /* If rexxsyslib.library opens cleanly it's time for
  5309.          * us to create the background term Rexx server.
  5310.          */
  5311.  
  5312.     if(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0))
  5313.     {
  5314.             /* Create a background process handling the
  5315.              * rexx messages asynchronously.
  5316.              */
  5317.  
  5318.         Forbid();
  5319.  
  5320.         if(RexxProcess = (struct Process *)CreateNewProcTags(
  5321.             NP_Entry,    RexxServer,
  5322.             NP_Name,    "term Rexx Process",
  5323.             NP_Priority,    5,
  5324.             NP_StackSize,    8192,
  5325.             NP_WindowPtr,    -1,
  5326.         TAG_END))
  5327.         {
  5328.             ClrSignal(SIG_HANDSHAKE);
  5329.  
  5330.             Wait(SIG_HANDSHAKE);
  5331.         }
  5332.  
  5333.         Permit();
  5334.  
  5335.         if(!RexxProcess)
  5336.             return(LocaleString(MSG_TERMINIT_UNABLE_TO_CREATE_AREXX_PROCESS_TXT));
  5337.     }
  5338.  
  5339.         /* Install the public screen name, assumes that the user
  5340.          * wants the window to be opened on the screen, rather than
  5341.          * opening a custom screen.
  5342.          */
  5343.  
  5344.     if(SomePubScreenName[0])
  5345.     {
  5346.         strcpy(Config -> ScreenConfig -> PubScreenName,SomePubScreenName);
  5347.  
  5348.         Config -> ScreenConfig -> Blinking    = FALSE;
  5349.         Config -> ScreenConfig -> FasterLayout    = FALSE;
  5350.         Config -> ScreenConfig -> UseWorkbench    = TRUE;
  5351.  
  5352.         SomePubScreenName[0] = 0;
  5353.     }
  5354.  
  5355.     CreateQueueProcess();
  5356.  
  5357.     Forbid();
  5358.  
  5359.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Name = RexxPortName;
  5360.     RendezvousSemaphore . rs_Semaphore . ss_Link . ln_Pri  = -127;
  5361.  
  5362.     AddSemaphore(&RendezvousSemaphore);
  5363.  
  5364.     Permit();
  5365.  
  5366. //    DebugInit();
  5367.  
  5368.     if(DoIconify)
  5369.         return(NULL);
  5370.     else
  5371.     {
  5372.             /* Create the whole display. */
  5373.  
  5374.         if(Result = CreateDisplay(TRUE))
  5375.             return(Result);
  5376.         else
  5377.         {
  5378.             PubScreenStuff();
  5379.  
  5380.             return(NULL);
  5381.         }
  5382.     }
  5383. }
  5384.